File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JCheckBox in JTable Rendering problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JCheckBox in JTable Rendering problem" Watch "JCheckBox in JTable Rendering problem" New topic

JCheckBox in JTable Rendering problem

pothineni rajesh

Joined: Dec 17, 2008
Posts: 18
Hi All,
I am using Jtable with checkboxes as groups and subgroups.
it's some thing like

CkeckBox Group1
Checkbox Sub1 1 2 3 4
Checkbox Sub2 2 3 3 3
CheckBOx Group2
Checkbox Sub3 1 2 3 4
Checkbox Sub4 2 3 3 3

when clicking on CkeckBox Group1 all checkboxes under group1 must be checked.i.e. checkBox sub1 and sub2 must be checked..viceversa for deseleceting the checkBoxGroup1.

similarly for checkBox group2 ..

but when I am trying to do the same when clciking on group2 then also subgroups of group1 are selected..
may be this is becoz of renderining problem..

any help???
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> may be this is becoz of renderining problem..

who knows?

the answer is in the code
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

Michael is correct. How are you setting the values? And what renderer are you using?

How To Ask Questions How To Answer Questions
pothineni rajesh

Joined: Dec 17, 2008
Posts: 18

I am adding the rows as something like the below..

dtm.insertRow(y,new Object[]{"","","",new Boolean(false),affUnsprung.getModelYear(),affUnsprung.getVehicleFamily(),affUnsprung.getVehicleLine(),affUnsprung.getPriceClass(),affUnsprung.getBodyStyle(),affUnsprung.getMarketSegment(),affUnsprung.getEngineSc(),affUnsprung.getGvwrSc(),affUnsprung.getPickupBoxSc(),affUnsprung.getMktSegQualSc(),affUnsprung.getGvwRating(),affUnsprung.getSalesCode(),affUnsprung.getOptConnectorCodes()});

this is the logic for getting the rows and subgroups..

rowRenderer1.add(y, checkBoxRenderer1);
rowEditor1.setEditorAt(y, checkBoxEditor1);

here adding the renderers



and the renderer and editor class as below..

class EachRowRenderer implements TableCellRenderer {
protected Hashtable renderers;

protected TableCellRenderer renderer, defaultRenderer;
public EachRowRenderer() {

renderers = new Hashtable();
defaultRenderer = new DefaultTableCellRenderer();

public void add(int row, TableCellRenderer renderer) {
renderers.put(new Integer(row), renderer);

public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) {
renderer = (TableCellRenderer) renderers.get(new Integer(row));
if (renderer == null) {
renderer = defaultRenderer;
return renderer.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);

Row Editor as follows:

class EachRowEditor implements TableCellEditor {
protected Hashtable editors;

protected TableCellEditor editor, defaultEditor;

JTable table;

* Constructs a EachRowEditor. create default editor
* @see TableCellEditor
* @see DefaultCellEditor
public EachRowEditor(JTable table) {

this.table = table;
editors = new Hashtable();
defaultEditor = new DefaultCellEditor(new JTextField());
I agree. Here's the link:
subject: JCheckBox in JTable Rendering problem
It's not a secret anymore!