wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JCheckBox in JTable Rendering problem" Watch "JCheckBox in JTable Rendering problem" New topic
Author

JCheckBox in JTable Rendering problem

pothineni rajesh
Greenhorn

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
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pothineni rajesh
Greenhorn

Joined: Dec 17, 2008
Posts: 18
Hi,

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);
y++;

here adding the renderers

affectedTable.getColumnModel().getColumn(3).setCellRenderer(rowRenderer1);

affectedTable.getColumnModel().getColumn(3).setCellEditor(rowEditor1);

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: http://aspose.com/file-tools
 
subject: JCheckBox in JTable Rendering problem
 
Similar Threads
Sorting 10 numbers
JTable
Add checkbox in JTable
JTable
Please help me