File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

programmatic change of text item color in JLIst

 
robyn byrd
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 886
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is JList.setSelectionBackground() not working for you?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic