Skip to main content

Dynamically add entries into a TreeModel & JComboBox

No replies
acnash
Offline
Joined: 2013-12-09
Points: 0

Hi all, first post here,

I'm having great difficulty combinging a JComboBox with the mechanism behind adding data dynamically into a table model.

To be clear, unlike many examples on the Internet when I say dynamically, I want data to appear in the table (via AbstractModelModel I guess) through user interaction, thus nowhere in the code are the JTable values hard coded. The idea is I have a Canvas3D component displaying the position of atoms. I click on a pair of atoms and a JTable appears. It is 1 row by 3 columns containing the name of the first atom, the second atom and then what I want to be a JComboBox of selectable information. You can click on two further atoms an additional row appear. I can happily add the data dynamically in this way into the first two columns, but I have no idea how I can get a JComboBox in the third column given that I have very modified AbstractTableModel.

I am after ideas beyond "use DefaultCellEditor", as this doesn't clear up the fact that I do not have any populated data upon loading the Java app, and as such I really don't know (a) what class I should be returning in getColumnClass(), or what I should be setting in the setValueAt() methods of AbstractTableModel.

I won't post any code at the moment, as mine is a complete mess with multiple attempts. I would really appreciate an example of adding two different types of data (String and a selection from a JComboBox) as a consequence of some user action, rather than the entries being hardcoded from the start as some Object[][] in AbstractTableModel.

All help is appreciated.
Thanks