• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help creating custom ComboBoxEditor

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone ever created a custom ComboBoxEditor to display JLabels w/ icons in a JComboBox? I'm looking at the methods in the ComboBoxEditor interface, but I'm not sure how to override getEditorComponent() to return what I want.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be looking more at the setRenderer( ListCellRenderer ) method... The ListCellRenderer renders the choices in the pull down combo box list. The ComboBoxEditor renders the editing area in an editable combo box. If you do override ListCellRenderer to show an icon and text in a JLabel, then you can override ComboBoxEditor to be a JPanel that holds a JLabel with an icon and a JTextField to edit the text...

Here's a short program that shows this...



-Nate
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the great reply! You've been a big help.
---Matt
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!