F
frafel
I need to insert in the cells of a particular jTable column, different
components; a good example could be:
In a table with two columns and three rows, referring to the second
column, I would like to put in the first cell (0, 1) a check box; in
the second cell (1, 1) a combobox with the items "one", "two", "three"
and I will left the third cell (2, 1) ready to accept a string from
the user (means that here I don't need to insert any one component).
I have seen that using the following snippets of code:
JCheckBox mycomp = new JCheckBox("prova", true);
mycomp.setVisible(rootPaneCheckingEnabled);
mycomp.setEnabled(true);
DefaultCellEditor editor = new DefaultCellEditor(mycomp);
TableColumnModel tcm = jTable1.getColumnModel();
tcm.getColumn(1).setCellEditor(editor);
or
String[] mio = {"uno","due","tre","quattro"};
JComboBox mycomp = new JComboBox(mio);
mycomp.setVisible(rootPaneCheckingEnabled);
mycomp.setEnabled(true);
DefaultCellEditor editor = new DefaultCellEditor(mycomp);
TableColumnModel tcm = jTable1.getColumnModel();
tcm.getColumn(1).setCellEditor(editor);
I can see the checkbox or combobox; but that components appears in all
the cells of the second column.
How I can change my code to reach my objective?
Thank you from Franco in Italy
components; a good example could be:
In a table with two columns and three rows, referring to the second
column, I would like to put in the first cell (0, 1) a check box; in
the second cell (1, 1) a combobox with the items "one", "two", "three"
and I will left the third cell (2, 1) ready to accept a string from
the user (means that here I don't need to insert any one component).
I have seen that using the following snippets of code:
JCheckBox mycomp = new JCheckBox("prova", true);
mycomp.setVisible(rootPaneCheckingEnabled);
mycomp.setEnabled(true);
DefaultCellEditor editor = new DefaultCellEditor(mycomp);
TableColumnModel tcm = jTable1.getColumnModel();
tcm.getColumn(1).setCellEditor(editor);
or
String[] mio = {"uno","due","tre","quattro"};
JComboBox mycomp = new JComboBox(mio);
mycomp.setVisible(rootPaneCheckingEnabled);
mycomp.setEnabled(true);
DefaultCellEditor editor = new DefaultCellEditor(mycomp);
TableColumnModel tcm = jTable1.getColumnModel();
tcm.getColumn(1).setCellEditor(editor);
I can see the checkbox or combobox; but that components appears in all
the cells of the second column.
How I can change my code to reach my objective?
Thank you from Franco in Italy