Skip to main content

HOw to get value in JCombobox in Jtable?

1 reply [Last post]
gee16
Offline
Joined: 2011-06-16
Points: 0

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.

Thanks

Gee

Reply viewing options

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

This should do the trick...

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