Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Change Table and Tree color when selected (vice versa)  RSS feed

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




 
Sheriff
Posts: 21426
94
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...

 
Bartender
Posts: 5167
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: 5167
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!