Swing/AWT/SWT :: Update JTable Cell Values Inside A Loop

Jan 5, 2015

I have a program where i want to indicate the user when i have completed a task which i am running inside a for loop. Below is my code.

for(Map.Entry<Double,SimplestCopyInstance> entry : myList.entrySet()){
double key = entry.getKey();
SimplestCopyInstance scp = entry.getValue();
Copy cp = new Copy();
cp.putLocations(scp.getSrc(), scp.getDes());
scp.setStatus(cp.baseCopy()+"");

[Code] ....

I have used netbeans to build my app. So there creating jTable is out of my control as that part was inside auto-generated code. I have just used the jTable.setValue().

My problem is, above method is inside a button click event. Updated values not displaying until the loops ends.

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Code Prevent Cursor From Moving When Inside A Cell Of JTable

Jun 24, 2014

Tried creating a simple sample but all works as expected.

The following code prevents the cursor from moving when inside a cell of a JTable.

public void keyPressed(KeyEvent e) {
if ( (e.getKeyCode() == KeyEvent.VK_KP_LEFT) || (e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
|| (e.getKeyCode() == KeyEvent.VK_RIGHT) || (e.getKeyCode() == KeyEvent.VK_LEFT) )
{
//Do nothing
e.consume();
}
}
});

When editing a cell, the existing code would use the right/left cursor keys to move from cell to cell as opposed to from character to character when editing a cell. I planned to override the functionality by tossing in the above code as a test to see if it stops the functionality before I override it.

After placing in the above code, the above functionality no longer occurs, but now the cursor moves within the cell as I wanted which is to move from character to character instead of cell to cell. Its great it works, but it really shouldn't. Essentially the default behavior has been restored when it should have really disabled the left/right keys.

I assume there is some underlying class someplace that is doing something to affect the behavior. Since a sample can't be provided I am wondering in what scenarios would the e.consume() restore default functionality?

View Replies View Related

JTable With ImageIcon - How To Use Array With 4 Values In Table Cell

Mar 22, 2015

I would like to create a JTable.
 
Each cell contains an array of 4 objects:

[0] ImageIcon
[1] ImageIcon
[2] Number
[3] Boolean

1) Once JTable is displayed, each cell display only [0] .
2) Later, based on user mouse click on cell, cell should display [1]
 
How can I use an array with 4 values in Table Cell?

View Replies View Related

Swing/AWT/SWT :: How To Get Double Value Into JTable Cell

May 29, 2014

My latest issue was that I wanted to only get a double value into a JTable Cell.

So first I Overrode the getCellEditor(int row,int col) method of my JTable, so if I was in a cell i knew I needed a double value I returned my Editor.

My editor filters out anything but numbers. I also check to make sure we get one and only one decimal point.

Other solutions Ive seen use keyboard Listeners, but to me that doesn't work. What if the user cuts and pastes data? My solution handles that as well.

It doesn't handle if they try to cut and paste something like 1234abcd.bob.123.23 , this would result in 1234..123.23 pasted in. I'll handle faulty values on the getValue method of my AbstractTable, but as long as the user is using mostly valid data this works well.

public TableCellEditor getCellEditor(int row, int col) {
if (row==TheRowWant && col==TheColumnI want) {
return (new DefaultCellEditor(createDoubleTextField()));
}
}
private JTextField createDoubleTextField() {
final JTextField field = new JTextField();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Peculiar JTable - Cell Value Vanishes

Aug 20, 2014

I am facing some peculiar issue with JTable.

Change value of a cell, without clicking on anywhere else, directly click on column (or) try to expand column size, value you entered in that cell vanishes. But if you click on any other cell instead of expanding column size, value will remain in cell. Not really sure how to fix this issue.

class SimpleTableExample
extends JFrame
{
// Instance attributes used in this example
privateJPaneltopPanel;
privateJTabletable;
privateJScrollPane scrollPane;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Custom JTable Renderer And Cell Editor

Jul 23, 2014

What I'm trying to do is make an inventory type program that includes a jtable. In the Jtable in the last column there will be 2 buttons and a textfield to register the value of additions or subtractions to the overal stock amount. (See screenshot in attachment).

As of now I am able to increment or decrement the numbers when the buttons are clicked on however the problem is that if I add 2 to the first row, and then go to add 2 to the next row or any other row for that matter, the value of the previous row is added to the next row, and the previous row reverts back to a value of 0. So basically its like there is only one editor that keeps track of one value no matter what row you are editing.

I need getting it so that I can add different values to each different row depending on the stock being used or received. The following is my code:

Main class

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 155, 643, 233);
IMG.add(scrollPane);
center = new centerJustify();
ts = new tableCellRenderer();
tm = new DefaultTableModel(){

[Code] .....

View Replies View Related

Swing/AWT/SWT :: JTable - Cell Keeps Focus After Clear Selection

May 7, 2014

I'm having a small problem using a jTable.

After calling the .clearSelection() methode of the table object, the cell clicked in when selecting the table row, keeps it's focus.

How do I remove the focus of the cell?

View Replies View Related

Swing/AWT/SWT :: Making A Custom Cell Renderer Work In A JTable?

Jan 24, 2014

Now my issue is I have a JTable. The first column will contain Date objects all the way to the bottom. I want the JTable to display only the month and year. I created a custom cell renderer, but it appears the cell renderer method "getTableCellRendererComponent" is never called. (I tested it using System.out.println();) Here is my code for setting the cell renderer and the contents of the first column:

MonthYearTableCellRenderer renderer = new MonthYearTableCellRenderer();
tblView.setDefaultRenderer(Date.class, renderer);
for(int i = 0; i < 60; i++){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.MONTH, i);
tableModel.setValueAt(cal.getTime(), i, 0);
}

The Date objects are set into the cells of column 0 correctly. The table shows the result of the "toString()" method for each cell in that column.

View Replies View Related

Swing/AWT/SWT :: Changing Color Of Jtable Base On A Row Of Cell Value In One Column

Feb 10, 2014

My code is

Double qty = 0.0;
for ( int i = 0; i < ingTable.getRowCount(); i++){
qty = (Double) ingTable.getValueAt(i,2);
if( qty < 30.0){
ingTable.setBackground(Color.red);
} else {
ingTable.setBackground(Color.white);
}
}

View Replies View Related

Swing/AWT/SWT :: Color To Persist In Cell Of Jtable After ComboBox Selection

May 29, 2014

I have a ComboBox I'm using for a cellEditor. The list of items in the comboBox might have colors behind them, which I've managed to render. What I haven't figured out is a good way to keep the color in the cell after the item is selected.I don't' want to have a persistent comboBox in the cell, i only want to see it when editing that cell.

public TableCellEditor getCellEditor(int row, int col)
{
if (row==theRow && col==theCol)
{
JComboBox<?> combo = new JComboBox<Object>(getPickListEntries());
combo.setRenderer(new PickListRenderer(combo));
combo.setBorder(BorderFactory.createEmptyBorder());
}

[code]....

View Replies View Related

Swing/AWT/SWT :: Copy Selected Data From JTable Cell To Clipboard

Feb 18, 2014

I have a jtable that I would like to copy from a cell that I select to clipboard. How could I do these.

View Replies View Related

Swing/AWT/SWT :: JTable Cell Renderer Causing Program To Go Black When Minimized

Aug 25, 2014

I'm making a program that selects classes from a database via a jcombo box and then populates a time table with the class times.

I've used a custom cellrenderer that extends DefaultTableCellRenderer to text wrap the information and change the background of the cells.

It works but when i minimize the program it goes all black and if I double click I get a new JTextArea opening up on the timetable and when I minimize the program and go to open it again i get an "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" and the cell render seems to be called again even though i haven't rerun the program.

This is the cell renderer that I built

public class TimesTableCellRenderer extends DefaultTableCellRenderer {
private int minHeight = -1;
private final JLabel label = new JLabel();
private final JTextArea textArea = new JTextArea();
public TimesTableCellRenderer(){
super();
textArea.setLineWrap(true);

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Change Color Of Column Header When Cell Is Clicked In JTable

Jan 20, 2015

I'm working on a spreadsheet-like table and I was able to set it so that it would highlight the first cell in the relevant row(titled 1,2,3.. etc) when a cell is clicked. (Just like in MS Excel - preview attached) Now I want to do the same to the column header(i.e. A,B,C,D....etc) . How can I do it?

private void formWindowOpened(java.awt.event.WindowEvent evt) {
setLocationRelativeTo(null);
int rowNum = sheet.getRowCount();
for(int i=0; i<rowNum; i++){
sheet.setValueAt(i+1, i, 0);

[Code] .....

Untitled.jpg

View Replies View Related

Swing/AWT/SWT :: Fitting Dynamic JTable Inside A Dialog Or Frame?

Apr 22, 2014

I want to calculate the height of a dialog that contain only a table depending on how many rows that table it has so I'm using the cross multiplication rule.For example i check initially that my table is well fitting into the dialog(Without space at the bottom) for some value and after that i use the cross multiplication rule because data are dynamic.But unfortunately this rule does not solve the problem.What's the best rule for fitting a dynamic table inside a dialog or a frame? Here is my code.

public class FlowLayoutChangingGap {
public static void main(String[] args) {
// just for testing perpose but data are getting from database and it's dynamic
Object[][] data = {
{ "Kathy", "Smith", "Snowboarding", new Integer(5) },
{ "John", "Doe", "Rowing", new Integer(3) },

[Code] ....

View Replies View Related

Java Array Update Without Using ArrayList - Add Values And Update Size?

Feb 9, 2015

I am trying to create an array list without using the built in arrayList class that java has. I need to start the array being empty with a length of 5. I then add objects to the array. I want to check if the array is full and if not add a value to the next empty space. Once the array is full I then need to create a second array that starts empty and with the length of the first array + 1.

The contents of the first array are then copied into the new array without using the built in copy classes java has and then the new array ends up containing 5 elements and one null space the first time round. The first array is then overwritten with the new array containing the 5 elements and the null space. The process then starts again adding values until the array is full which will be 1 more value then recreating the second array empty and the length of the first array + 1. This is my attempt at creating this but I have run into multiple problems where I get only the last value I added and the rest of the values are null:

public class MyArrayList {
public Object arrayList[];
public MyArrayList(Object[] arrayList) {
this.arrayList = arrayList;

[code]...

View Replies View Related

Swing/AWT/SWT :: How To Add Values From JComboBox To JTable Cells

Jul 16, 2014

How can I add values from a JComboBox to a JTable ? I've created a drop down list and a button and I want the values to be added to a table whenever i click on the button (add).

View Replies View Related

JavaFX 2.0 :: TableColumn CellValueFactory Invoked For Every Cell Update - Normal?

Apr 10, 2015

I have a JavaFX 8 TableView with multiple columns.  The CellValueFactories for the columns are set as:
 
xxxColumn.setCellValueFactory(new ItemCountFactory(itemName));  

where itemName is a String identifying a different item for each column.
 
ItemCountFactory returns a StringBinding as the cell value, as follows:
 
    public ObservableValue<String> call(CellDataFeatures<Category, String> rowData) {
        return new ItemCountBinding(rowData.getValue(), itemName);
    }
 
where
     class ItemCountBinding extends StringBinding {
     ...
          protected String computeValue() {
                    String cellValue = ...;
                    return cellValue;
          }
     }

The StringBinding depends on properties of the Category instance for the table row.  The correct data is displayed okay, but I have noticed that every time one of the Category properties changes (i.e., every time a cell value changes), ItemCountFactory is called again to create a new StringBinding.  I would have expected the Factory to be invoked just once for each cell during initialization, and then the table column would monitor the returned Observable object.  Instead it seems to be creating a new Observable object every time the cell value changes.  Is this normal, or am I doing something wrong?  Same behavior on Java 8u20 and 8u40.  If it is not the expected behavior, I will write an example test program; I do not want to post the current full source code.
 
The table items are set just once, with:

     countTable.setItems(categoryList);

where categoryList is of type ObservableList<Category>.  The list itself is not modified after being associated with the table; i.e., no rows are added or deleted or replaced.

View Replies View Related

JButton In A JTable Cell

Aug 19, 2014

How do i parse a String of text in a JTable Cell to work as a button?For example lets say a row of IDs such as 1,2,3,4,5,6 id like the whole column to parse as JButtons that are titled 1,2,3,4,5,6..Id like to then use these buttons to call a function with the title as a parameter.Its just a simple row of entries where the button will open up an edit screen to edit the corresponding clicked entry.So how do i parse them as buttons for a start?

View Replies View Related

JTable Specific Cell Selected

Jun 6, 2014

I want perform some calculations whenever a specific cell block is focused in JTable, I've tried using focusListener on JTable but looks like my table isn't triggering the event. I don't know why, what to do?

View Replies View Related

Key Binding JTable Cell Entries

Jul 8, 2014

I have an editable JTable that has a lot of JComboBox's as cell entries. I would like to be able to "arrow over" to said cell, and with a pressing of either a numerical button or by typing the first letter of the String selection (possibly followed by a second), be able to select the appropriate selection from the cell's JComboBox. I have tried to add a key listener to the JComboBox itself, which works given that I click on said cell and show its menu.

How would I go about ensuring that, when focus is on the cell itself, and I start typing, the appropriate selection is chosen?? (I think this might get into key binding, but I don't know if I have to try it from the scope of JTable, or from that JTable's TableModel (which I have made my custom version of).

Here is what I have so far (everything but SandwichNumber, SandwichName, and Oregano uses JComboBox): [URL] ...., how would I do such key binding?

View Replies View Related

How To Merge Cell In DefaultTableModel / JTable

Feb 18, 2014

I searched a lot and got some answers for this Q. but many of them referred to links which give 404 error. I want to make table like this:

Can I make this in Java?

View Replies View Related

Jtable Cell With Search Depends On Value Entered?

May 31, 2014

I am trying to do the fallowing ,

Jtable cell with search (% like) depends on the value entered

if i enter "mi" it should show all data begin with "mi" from my data set

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

While Loop Inside A For Loop To Determine Proper Length Of Variable

Feb 25, 2014

Here's the code: it's while loop inside a for loop to determine the proper length of a variable:

for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "

[code]....

I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.

View Replies View Related

Custom Jtable Cell Editor Throwing Illegal Component State Exception

Jul 10, 2014

I've come across an interesting problem when using a Jcombobox as a custom cell editor(and renderer) in a jtable. I was hoping to add a keybinding in order to display the dropdown of the combobox instead of having to click on it however, when I make a call to showPopup() I get:

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location Which is strange as my jtable is visible and the editor/renderer seems to be working fine.

Here's the cell editor + renderer I'm using:

class MyComboBoxRenderer extends JComboBox implements TableCellRenderer {
public MyComboBoxRenderer(String[] items) {
super(items);
} public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());

[code]....

View Replies View Related

JSP :: Update Database Values?

Jan 4, 2015

I am trying out jsp and servlets now for the first time. I have to insert two data, car code and car name into a mysql table. I got those details using jsp but if I use form, it redirects to another page for insertion. I want the data to be inserted and still remain in same jsp page. I am thinking of using onClick from javascript but as I googled this many places have said it is a bad idea to use jsp inside javascript. If so how can we insert data to mysql table without redirecting to another page?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved