| 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: 19216
|
|
|
What kind of TableCellEditor are you using?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1790
|
|
|
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: 19216
|
|
|
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: 1790
|
|
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: 1790
|
|
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.
|
 |
 |
|
|
subject: JTable not showing combobox dropdown arrow
|
|
|