How do I create a JTable with alternating background row coloring?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dan_Merkel
Posted On:   Friday, April 13, 2001 08:23 AM

How can I create a JTable with alternating background row coloring?


I have assigned my own cell renderers on a column basis, using the TableColumn.setCellRenderer() method.


Is this the right approach?


Before the cell renderer renders the cell, is there anyway to determine the row that it is currently "on"? If so, I could set the background color at this point.


Thanks for your help.
dan

Re: How do I create a JTable with alternating background row coloring?

Posted By:   Nischala_Kale  
Posted On:   Friday, April 13, 2001 02:23 PM

Extend DefaultCellRenderer, override the method public Component getTableCellEditorComponent(JTable table,
Object value,
boolean isSelected,
int row,
int column)

You can set different background colors for odd and even rows.

Also, make sure to check the isSelected flag, so you can set the background color of the selected cell correctly
About | Sitemap | Contact