This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable not showing combobox dropdown arrow

 
Lou Caudell
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of TableCellEditor are you using?
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, I am not at liberty to post the code. Thanks for the incite.
 
Lou Caudell
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic