| Author |
JTable cell color URGENT
|
shashikant kulkarni
Greenhorn
Joined: Jan 28, 2002
Posts: 3
|
|
Hi All How to change the color of the cell (not the entire row)depending on the value present in it? Thanks...
|
 |
Vinod Venugopal
Ranch Hand
Joined: Dec 06, 2000
Posts: 148
|
|
Hi, You can set the color for a single cell by setting a CellRenderer to a column & then check for row & column. First : TableColumnModel colmod = table.getColumnModel(); colmod.getColumn(0).setCellRenderer(new ColorRenderer()); Second: class ColorRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable myTable, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(myTable, value, isSelected, hasFocus, row, column); if(isSelected == false){ setBackground((((row == 1)) && (column == 0))// particular cell ? (Color.blue) : Color.red)); } return this; } } . . . You can change row ==1 or column == 1 check by even getting cell value using myTable.getValueAt(row,column).toString("...") if you want to check otherwise. Vinod
|
- Vinod<br />-------<br />SCJP2
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4120
|
|
shashikant, Please re-regiester with a user name that follows the JavaRanch Official User Name Policy. You are required to have a user name in the format "First Name" + space + "Last Name". Thanks, -Nate
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
 |
|
|
subject: JTable cell color URGENT
|
|
|