简体   繁体   中英

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!

尝试:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM