my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes problem in colors of cells JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem in colors of cells JTable " Watch "problem in colors of cells JTable " New topic
Author

problem in colors of cells JTable

aminur rashid
Ranch Hand

Joined: Sep 21, 2001
Posts: 79
Hi.
My Problem is.
I have a JTable with 2 columns ( Rows can be 1-10 depending upon the size of
input vector)
I have provided two button in my Frame
1)Update Row
2) Update whole Table.
Now i want I want that if a user makes a change in any cell say cell( row
3,Col 1) ;and moves to next row , then the color (background/foreground) of
that cell should change to any other color .Again if he presses any of the
button then the default color of the cell should be restored.Basically i
want to indicate the user that he has made changes in the cell and he needs
to press the button for updation
Now i have wriiten code as
protected JTable rationalDescTable = new JTable(myModel) { public TableCellEditor getCellEditor(int row, int col) { if (edited)//boolean checks is someone has edited the cell or not { return new DefaultCellEditor(new JTextField()) { public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column) { super.getTableCellEditorComponent(table, value, isSelected,row, column);JTextField textField = (JTextField)super.getTableCellEditorComponent(table, value, isSelected, row, column); rationalDescTable.changeSelection(row,column,false,false);textField.setBackground(Color.red);textField.getCaret().setSelectionVisible(true);textField.setFont(new Font("SansSerif",Font.ITALIC,12));textField.setSelectionColor(Color.red); // Option return textField;} }; } else { return new DefaultCellEditor(new JTextField()) { public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column) { super.getTableCellEditorComponent(table, value, isSelected,row, column);JTextField textField = (JTextField)super.getTableCellEditorComponent(table, value, isSelected, row, column); rationalDescTable.changeSelection(row,column,false,false);textField.setBackground(Color.blue);textField.setForeground(Color.white);//textField.selectAll();//textField.setFont(new Font("SansSerif",Font.ITALIC,12));textField.getCaret().setSelectionVisible(true);textField.setSelectionColor(Color.blue);return textField; } }; } }

but the problem is that when i click the button the backgrounnd of cell is not changed from red to blue.In the action listener events of button i have made edited as false.
Regards
Md Aminur Rashid
Pune

Regards<br />Aminur
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem in colors of cells JTable
 
Similar Threads
JTable numeric validation
Date in JTable
problem in colors of cells JTable (check this one)
jtable alert
Help updating cells in a JTable