permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes Change Table and Tree color when selected (vice versa) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Change Table and Tree color when selected (vice versa)" Watch "Change Table and Tree color when selected (vice versa)" New topic
Author

Change Table and Tree color when selected (vice versa)

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Oct 27, 2005
Posts: 19656
    
  18

You should start by adding a ListSelectionListener to the table (through its selection model).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: May 03, 2008
Posts: 4523
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: May 03, 2008
Posts: 4523
    
    5

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Change Table and Tree color when selected (vice versa)
 
Similar Threads
JTree
need help with jTree isNodeAncestor()
DND from JTree to JTable
JTable In JTree
Problem with JTree inside JScrollPane inside JPanel