This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
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

Could we replace the dropdown of a JCombo Box by an other component, like a JTable component?  RSS feed

 
John-Philippe Verger
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,

My question is related to combo boxes.
A combo box in general is a text field with a dropdown list. I would want to know if we can replace hthe dropdown List by an other component, for example a JTable component.
Thanks.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. You will need to provide a custom renderer.
More on it here http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A custom renderer would still render in a JList. Not replace the dropdown with a table.

I've done this by adding a PopupMenuListener to the JComboBox and implementing this one method: (Java 8 code)In that code, LocalDateCombo is the outer class, that extends JComboBox, and popupMenu is a JPopupMenu to which a JPanel has been added. To use a JTable you would probably want to wrap it in a JScrollPane or add the table header and the table to a BoxLayout.VERTICAL or other suitable layout and add that to the JPopupMenu.

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