This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

TableCellEditor ComboBox in JTable  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on getting a JTable to display a different combo box in each row. I have successfully had this happen, however, there is initially nothing shown in the table cell until I click and select from the options.

My process is to create a new JComboBox with all the options then attach it to the JTable through a TableCellEditor.

I'm not sure if it's a repaint issue or if I need to select the option in the combo box in a certain way. All I need is to have the first option in the combo box shown in the table.
 
Author
Ranch Hand
Posts: 964
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by John Forsyth:
I'm working on getting a JTable to display a different combo box in each row. I have successfully had this happen, however, there is initially nothing shown in the table cell until I click and select from the options.

My process is to create a new JComboBox with all the options then attach it to the JTable through a TableCellEditor.

I'm not sure if it's a repaint issue or if I need to select the option in the combo box in a certain way. All I need is to have the first option in the combo box shown in the table.



So the cell renderers are ok? It's just the editor you're having trouble with?

It doesn't sound like a repaint issue. The editor's combo box should be set to match the current value of the cell (from the table model's getValueAt() method), regardless of which index it has. If the current value of the cell doesn't match any of the combo box's items then it will usually act as you describe.

It should be possible to modify the editor so that it will display first combo box item if the value doesn't match any of its items if that's really what you want. Depending on what you are trying to do, it may be better to modify your table model instead.
[ August 04, 2008: Message edited by: Brian Cole ]
 
John Forsyth
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've figured out that my issue was that while I was setting the selected index, I needed to select the actual value. It will now display the first item in the table.
Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!