• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to set JComboBox items in a JTable.

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a JTable that contains two columns. I use a JComboBox in column 1. I follow the example in Swing Tutorial. However, i am trying to display an appropriate item among JComboBox's items for every row in JTable. I assume i have to iterate throught all rows in the table, in each row i have to extract the object in column 1 and call setSelectedItem() on this JComboBox object. However, i am not sure the way i setup the column according to the tutorial will allow me to achieve my goal. Also, how can i get the JComboBox object in a column? Thanks.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to call setSelectedItem. If you set the value of the cell it takes care of that for you setValueAt() method. I am not sure what problem you are having.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!