• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Change Table and Tree color when selected (vice versa)

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a main split pane. In the left component of the split pane there is a scroll pane and a table inside the scroll pane. On the right component of the split pane there is a scroll pane and a tree inside the scroll pane. Now I have to change the selection background of the tree and table when one of them are selected. Say if I have selected a column in the left table and then when I select a node on the right tree, then the table selection background should turn gray in color. And vice versa should happen when I select a tree and then the table.

It just like showing the user the current selection in Blue colour and the previous selection in Gray color. I am using a TreeCellRenderer just to set the images for the icons in the tree.

I have managed to write this SSCCE... I believe the code should be written in TableListener... Correct me if I am wrong... Thanks!

I have managed to turn the color of table... but do not know how to change the color of selection in the tree...




 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should start by adding a ListSelectionListener to the table (through its selection model).
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

I override the valueChanged() method of the JTable like below. I am ignorant on how to change the color of the JTree in below method...

 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am ignorant on how to change the color of the JTree in below method...

Looks like you've missed the point of the SSCCE, which should demonstrate only the problem you are facing.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Burke,

I thought the SSCCE better show the requirement... you caught me twice in posting SSCCE... My Old Post... i hope i will post a better one next time...

And the solution worked like a charm

Thank you!
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an SSCCE for the solution. Your SSCCE for the problem would possibly contain an empty actionPerformed(...) for the button.Remember, the shorter your code, the more members will read it; and more of those who do read it will understand where your problem lies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic