Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox and ListCellRenderer Problem  RSS feed

 
Markus Schmider
Ranch Hand
Posts: 148
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am trying to use a JComboBox with a simple ListCellRenderer





The JCombox shows and odd behavior, when I point to an item it moves up or down and an empty line appears under the cursor.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have an answer, just a couple of suggestions:
  • Compare your code with class javax.swing.DefaultListCellRenderer
  • Make your class extend javax.swing.DefaultCellRenderer
  •  
    m beardsley
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Markus, try this… (I'm guessing your example doesn't work because by default JLabel is not opaque, so it won't show a background.)



    You can also use the UIManager and override the selection background color for all combo boxes. Just make sure you "put" the ColorUIResource into the defaults before you display your first window.

     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!