• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JList focus issue

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic