wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTable not showing combobox dropdown arrow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable not showing combobox dropdown arrow" Watch "JTable not showing combobox dropdown arrow" New topic
Author

JTable not showing combobox dropdown arrow

Lou Caudell
Ranch Hand

Joined: Oct 06, 2001
Posts: 32
I have a JTable with a model class that extends DefaultTableModel. The model list is composed of a decorated class which is an hibernate table row.
This row contains a couple of entities which are lists that will be rendered as JComboBoxes in the table. My issues is that at runtime the combo boxes do not show the drop down arrow customarily seen with JComboBoxes. I used a DefaultComboBoxModel straight up.
Can someone tell me how to make the drop down arrows appear.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

What kind of TableCellEditor are you using?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2204
    
    7
Read the section from the Swing tutorial on How to Use Tables for a working example that shows how to use a combo box as an editor.
Lou Caudell
Ranch Hand

Joined: Oct 06, 2001
Posts: 32
I should clarify that the drop down arrows do appear when clicked on, but go away when cell is refocused.

DefaultCellEditor is used for every column.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

So in other words, you want to display the combo box for rendering as well? Then just create a renderer that displays a combo box.
Lou Caudell
Ranch Hand

Joined: Oct 06, 2001
Posts: 32
Other tables in this app with JComboBox columns show the row cell with the drop down arrow, this one shows a blank field until clicked on. I both cases renderers have been written, but not necessarily editors.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2204
    
    7
Other tables in this app with JComboBox columns show the row cell with the drop down arrow


Well, then look at the code for the other tables to see how they do it. Use a combo box as a render implies someone has written custom code. We can't guess what you are doing differently.
Lou Caudell
Ranch Hand

Joined: Oct 06, 2001
Posts: 32
Unfortunately, I am not at liberty to post the code. Thanks for the incite.
Lou Caudell
Ranch Hand

Joined: Oct 06, 2001
Posts: 32
The primary factor in this problem turns out to be calling table.removeAll() in the refresh routine, which removes the renderers from memory.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2204
    
    7
I have no idea why you would be using the removeAll() method. That would typically be used for removing components from a JPanel. It is not applicable to the table.

However, if you have refresh code to refresh the data in the TableModel and are using the table.setModel(...) method, then yes this will cause all custom renderers to be lost. One way around this is to use

table.setAutoCreateColumnsFromModel( false )

after creating the table and model the first time. This will retain the renderers but only refresh the model.
 
Consider Paul's rocket mass heater.
 
subject: JTable not showing combobox dropdown arrow