Change your itemStateChanged(ItemEvent e)
method in next way:
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED){
voilPart.addRow(new Object[] { "col1", "col2",
"col3", "col4", "col5",
new Boolean(false), new Boolean(false), "col8" });
}
}
Also I recommend you to:
1)Use setLayout(null);
and setBounds()
methods instead of the, try to use LayoutManager
, try to start from FlowLayout
and BorderLayout
it's really simple.
2)For setting size of your JFrame
use method pack()
;
3)I think that entetes
it's column names create your TableModel like next
DefaultTableModel voilPart = new DefaultTableModel(new Object[][]{},entetes);
4) Set voilPart
as instance variable for using it in itemStateChanged()
method for adding a new row.
5) This isn't important code, you can delete it, because it's local variable that never used :
new AbstractTableModel() {
public int getColumnCount() {
return 0;
}
public int getRowCount() {
return 0;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return null;
}
public boolean isCellEditable(int row, int col) {
if (col == 4) {
return true;
} else {
return false;
}
}
};
6) add your table to JScrollPane
for scrolling.
Usefull liks: