..just using the JTable default behaviour, the clue is to override the
public Class getColumnClass(int column) method.
Code:
class ATableClass extends JTable {
public Class getColumnClass(int column) {
try {
if (column == 0) {
return Class.forName("java.lang.Boolean");
}
return Class.forName("java.lang.Object");
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
return null;
}
}
}
public class TableExample1 extends JFrame {
JScrollPane jScrollPane1 = new JScrollPane();
ATableClass tableOne = new ATableClass();
DefaultTableModel model = new DefaultTableModel();
Boolean [] boolArray=new Boolean[] {
new Boolean(true),
new Boolean(false),
new Boolean(true),
new Boolean(false),
new Boolean(true),
new Boolean(false)
};
public TableExample1() {
try {
jbInit();
tableOne.setModel(model);
model.addColumn("CbxColumn", boolArray);
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TableExample1 tex = new TableExample1();
tex.setBounds(10,10,300,200);
tex.setVisible(true);
}
private void jbInit() throws Exception {
this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(tableOne, null);
}
}
Bookmarks