I want to highlight the entire row when a user clicks on a cell of a JTable
My JTable has following -> CheckBox in column 0; strings in columns 1,2,3; Combo Box (Custom Rendered) in col 4, and other strings in col 5,6,7.
Also the Table has a Select All Check Box (Rendered using Custom CheckBoxHeaderRenderer).
Since there are multiple custom renderers used in the Table i need guidance on below few things.
1. Can I HIGHLIGHT (i.e. change ForeGround to selection foreground color) for the ENTIRE ROW when i click the checkbox in Column 1? - Since the Table is big in width this will allow users to know which row they have just selected?
2. Can I HIGHLIGHT the entire row when i click on the ComboBox present in col 4 - This is rendered using a Custom combo box renderer?
3. Can I HIGHLIGHT the entire row when i click any of the other cells (normal string value cells) present in the row?
4. Can I HIGHLIGHT the entire table (all rows & columns) when I select the Check Box present in my Column 1 HEADER of the JTable?
Sure, you can do anything you like in your TableCellRenderer. In particular your renderer knows whether the row containing the cell is selected -- providing your table's selection model works by rows. It can even look at other information, like for example that check box in column 1 header, and act accordingly.
Joined: May 31, 2011
Thanks for your reply. For now I think the highlight of the entire row should be OK when a particular cell is selected. After seeing your reply i just changed my selection mode to row selection by commenting cell selection like below.