Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JList focus issue  RSS feed

 
Travis Kline
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
When working with JList, JDK 1.2.2, I would like to indicate the component having focus by drawing a yellow border around the first cell in the list. I would expect this to be default behavior for this component. Is there any easy way to achieve this result without creating my own ListCellRenderer? Any tips would be appreciated....
Thanks much,
Travis
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the easiest way would be to make your own subclass of DefaultListCellRenderer... if you just wanted to set the selection color to yellow it would just consist of calling setSelectionBackground( Color.yellow ), but since you want a border, you're going to have to make your own renderer...
 
Travis Kline
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply!
I think you may be right, inevitably I will have to create my own renderer. But I have been studying some other windows based list components that behave differently. Just as a JButton will have an outline drawn around its edge when it receives focus, so should the JList's first cell (the yellow cell border may vary depending on L&F). All of the list examples I've seen coded outside of Java exhibit this behavior. It leads me to believe that it is either a bug or I am missing something....correct me if I'm wrong.
Thanks,
Travis
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!