• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Row Highlight on a JTable

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 26771
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!

 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic