Can I add a JTable as an item in a JComboBox?

Sandip Chitale

The SwingSet Demo has an example which shows a use of DefaultTreeModel, a custom ComboBoxModel implementation "TreeToListModel" ,custom JComboBox subclass "TreeCombo" and a custom ListCellRenderer implementation "ListEntryRenderer" to show a tree structure in a JComboBox dropdown.

You may find this example under J2SE 1.2 installation directory in

<jdk1.2.2 dir>/demo/jfc/SwingSet/src/

You should be able to achieve the same using

  • TableModel implementation
  • custom JComboBox subclass "TableCombo"
  • custom ListCellRenderer implementation "ListEntryRenderer"
  • custom ComboBoxModel implementation "TableToListModel"

JTree is a single column similar to JList. Whereas the JTable is multicolumn. Therefore you may have to draw on the way JTreeTable has been implemented which can be found on the Swing Connection website -

The JTreeTable uses a JTree as a TableCellRenderer for a JTable.

You may have to use a JTable as a ListCellRenderer of the dropdown JList of the combobox.

This not the coded example. Howevere all the information and samples should be enough to implement what you want.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact