Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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
Posts: 965
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!
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!