I got a (more or less) empty JTable in my GUI without any JCheckBoxes in the beginning. After a button is pressed I want to fill the table with names (Strings) and JCheckBoxes depending on the content of an array. The part with the names already works fine but I'm not able to change the class of single cells to boolean, instead a true or false appears in the JTable where the JCheckBox actually should be. I know that you can fill a complete column with JCheckBoxes if you set the column type to boolean in the beginning.
My question now is if it is possible to change the column typ of a single cell.
This is the code where the JTable is created:
table = new JTable();
table.setRowMargin(3);
table.setRowHeight(25);
table.setFillsViewportHeight(true);
table.setModel(new DefaultTableModel(
new Object[][] {
{null, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"},
{"", "2016-02-29", "2016-03-01", "2016-03-02", "2016-03-03", "2016-03-04"},
{" 1. Lesson", null, null, null, null, null},
{" 2. Lesson", null, null, null, null, null},
{" 3. Lesson", null, null, null, null, null},
{" 4. Lesson", null, null, null, null, null},
{" 5. Lesson", null, null, null, null, null},
{" 6. Lesson", null, null, null, null, null},
{" 7. Lesson", null, null, null, null, null},
{" 8. Lesson", null, null, null, null, null},
{" 9. Lesson", null, null, null, null, null},
{" 10. Lesson", null, null, null, null, null},
},
new String[] { "Empty", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }
)
{
Class[] columnTypes = new Class[]
{
String.class, Object.class, Object.class, Object.class, Object.class, Object.class
};
public Class getColumnClass(int columnIndex)
{
return columnTypes[columnIndex];
}
});
table.setBorder(new LineBorder(new Color(0, 0, 0)));
table.setBounds(381, 11, 518, 300);
panel.add(table);
This is the part where the content of the JTable is changed:
public void tableUpdate(Object[][] a)
{
for(int row = 0; row < 11; row++)
{
for(int column = 0 ; column < 5; column++)
{
table.setValueAt(a[column][row], row+1, column+1);
}
}
}
If you need further information please ask me and many thanks in advance.