This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes programmatic change of text item color in JLIst 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 "programmatic change of text item color in JLIst" Watch "programmatic change of text item color in JLIst" New topic
Author

programmatic change of text item color in JLIst

robyn byrd
Greenhorn

Joined: Oct 26, 2005
Posts: 9
I have a GUI consisting of a JList and JButton. The JList displays text items in black. When an item is selected the background color changes to red. I want to have the color of the selected text change to white when the user clicks on the JButton. In other words, the text color for the (already) selected item should change without requiring the user to click on the text item again. Can you show me how to accomplish this?
Thank you.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
create a boolean flag (field)

button's actionListener: change flag to true and repaint

listSelectionListener: change flag to false

listRenderer: set foreground
if(isSelected && flag) white
else black
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Is JList.setSelectionBackground() not working for you?


bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: programmatic change of text item color in JLIst
 
Similar Threads
FocusListener
Changing the text colour of JList items
problem selecting JList item
Won't repaint!
How to make JComboBox flash (red color)?