This is working example only ... Yes..its from tutorial ...but I have implemeted same way in my code ...
Given below are the steps showing the way I am implementing ...
1st ...
I am making object array with checkboxes .. and adding it to model ...
Object[][] data =
{
{new javax.swing.JCheckBox() , "test"},
};
DefaultTableModel model = new DefaultTableModel(data, columnNames);
2nd..
Implementing getColumnClass()
JTable table = new JTable( model )
{
public Class getColumnClass(int column)
{
return getValueAt(0, column).getClass();
}
};
3rd..
Implementing table cell renderer
class MyCellRenderer implements TableCellRenderer
{
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
Component com = (Component)value;
return com;
}
}
4th..
fuction call to
table.setDefaultRenderer(Component.class, new MyCellRenderer());
As I said earlier...
I am getting checkboxes in the column ...
But the issue is I am not able to check or select them ...