aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Row Highlight on a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Row Highlight on a JTable" Watch "Row Highlight on a JTable" New topic
Author

Row Highlight on a JTable

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi,

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?

Apologies if my question is misleading!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi Paul,

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.

// this.setCellSelectionEnabled(true);
this.setRowSelectionAllowed(true);

Now this highlights the whole row which suffices my requirement for now. Thanks much!!!

 
 
subject: Row Highlight on a JTable