• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Change Table and Tree color when selected (vice versa)

 
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 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...




 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic