This may be a vague query, so please pardon me.
Customized JTable (I\'ve modified the query and will discuss based on the SSCCE provided). I\'ve to create a JTable t
You can use the Boolean
wrapper class instead of the raw type and write your own TableCellRenderer
and override the getTableCellRendererComponent(..)
method.
public class CustomTableCellRenderer extends DefaultTableCellRenderer
{
public CustomTableCellRenderer()
{
super();
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if(value instanceof Boolean)
{
if(value != null)
{
JCheckBox jcb = new JCheckBox();
jcb.setSelected((Boolean) value);
return jcb;
}
return new JPanel();
}
return this;
}
}
Then just simply set infos.setDefaultRenderer(Boolean.class, new CustomTableCellRenderer());
and replace your raw types in the array with new Boolean(true)
. Wherever you don't want to have a JCeckBox
you put a null
instead of a Boolean
and an empty JPanel
will appear.