Skip to main content

HOw to get value in JCombobox in Jtable?

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2011-06-16

Hi All,

In my DefaultTableModel's Jtable one column has JCombobox. My problem is when i click the button it should display the selected value of perticular row's Combobox value. I am using getValueAt for getting Other columns values. But i don't know how to get values in Jcombobox in Jtable. Any one Can help me?

Sample Code:
public String[] values = {"A", "B", "C"};
JComboBox combo = new JComboBox(values);
TableColumn tbcol = table1.getColumnModel().getColumn(2);
tbcol.setCellEditor(new DefaultCellEditor(combo));

I ahve render also.But if the user not slected anything,in model.getDateCetor null value is coming.



Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2011-07-01

This should do the trick...

JComboBox combo = (JComboBox) table1.getCellEditor(row, column);
Object selectedItem = combo.getSelectedItem();