assertEquals(0, model.getColumnCount());
assertEquals(0, model.getRowCount());
}
public void testRender() {
Table table = new Table();
table.setDefaultRenderer(Object.class, new TableCellRenderer() {
public Component getTableCellRendererComponent(Table table, Object value, int column, int row) {
switch (column) {
case 0:
case 1:
return new Label(value.toString());
case 2:
CheckBox checkBox = new CheckBox();
checkBox.setSelected(((Boolean) value).booleanValue());
return checkBox;
default:
throw new IndexOutOfBoundsException();
}
}
});
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.setColumnCount(3);
model.insertRow(0, new Object[]{"Bob Johnson", new Integer(32), Boolean.TRUE});
model.insertRow(1, new Object[]{"Bill Simmons", new Integer(27), Boolean.TRUE});
model.insertRow(2, new Object[]{"Tracy Smith", new Integer(54), Boolean.TRUE});
model.insertRow(3, new Object[]{"Cathy Rogers", new Integer(21), Boolean.FALSE});
model.insertRow(4, new Object[]{"Xavier Doe", new Integer(77), Boolean.TRUE});
table.validate();
assertEquals(18, table.getComponentCount());
Component[] components = table.getComponents();
for (int i = 3; i < components.length; ++i) {
if (i % 3 == 2) {
assertEquals(CheckBox.class, components[i].getClass());
} else {
assertEquals(Label.class, components[i].getClass());
}
}
assertTrue(components[0] instanceof Label);
assertEquals("A", ((Label) components[0]).getText());
assertTrue(components[5] instanceof CheckBox);
assertTrue(((CheckBox) components[5]).isSelected());
assertTrue(components[8] instanceof CheckBox);
assertTrue(((CheckBox) components[8]).isSelected());
assertTrue(components[14] instanceof CheckBox);
assertFalse(((CheckBox) components[14]).isSelected());
assertTrue(table.getCellComponent(0, 0) instanceof Label);
assertEquals("A", ((Label) table.getCellComponent(0, Table.HEADER_ROW)).getText());
assertTrue(table.getCellComponent(2, 0) instanceof CheckBox);
assertTrue(((CheckBox) table.getCellComponent(2, 0)).isSelected());
assertTrue(table.getCellComponent(2, 1) instanceof CheckBox);
assertTrue(((CheckBox) table.getCellComponent(2, 1)).isSelected());
assertTrue(table.getCellComponent(2, 3) instanceof CheckBox);
assertFalse(((CheckBox) table.getCellComponent(2, 3)).isSelected());
}