TheRealJimShady
TheRealJimShady

Reputation: 4303

Return JComboBox from JTable

so I've got a number of JComboBox's which make up a JTable. My question is; without having access to these JComboBox's directly, how can I obtain them from the JTable? Below is how I've put the JComboBoxes into the JTable...

TableColumn columnModel = table.getColumnModel().getColumn(i);
columnModel.setCellEditor(new DefaultCellEditor(combo));

...So I would imagine that you can return them by doing something like...

JComboBox retrievedDropDowns = (JComboBox)table.getColumnModel().getColumn(1).getCellEditor();

But apparently not...

Am I far off?

Thanks!

Upvotes: 1

Views: 144

Answers (2)

oliholz
oliholz

Reputation: 7507

If you put a DefaultCellEditor in your columnModel then it will return a DefaultCellEditor not a JComboBox.

But you can use DefaultCellEditor.getComponent() to get the inner editorComponent.

Upvotes: 1

ogzd
ogzd

Reputation: 5692

Try:

JComboBox retrievedDropDowns = (JComboBox)table.getColumnModel().getColumn(i).getCellEditor().getComponent();

Upvotes: 2

Related Questions