Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display a JComboBox in a JTable column with different values  RSS feed

 
Jorge Maldonado
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Java and Swing and I need to include a JComboBox in a JTable column. The combobox should not necessarily display always the same items because such items depend on the values of other 2 columns in the same row.
I found the following code in http://www.coderanch.com/t/451389/GUI/java/Swing-JCombobox-JTable but I do not know how to implement it.
I actually have a test project with a JTable and some data that I typed directly. This JTable has a "blank" column where I need to display the JComboBox with values of other 2 columns of the same row. I also have a JButton and I want to fill the JComboBoxes when it is clicked.
I will very much appreciate if you tell me how can I use the class below when clicking the button.



Resdpectfully,
Jorge Maldonado
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example that shows how to dynamically change the model used by the combo box when the cell is edited:



So you would need to customize the code in the "getCellEditor(...)" method to meet your requirements.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!