Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JCheckBox in JTable Rendering problem

 
pothineni rajesh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> may be this is becoz of renderining problem..

who knows?

the answer is in the code
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael is correct. How are you setting the values? And what renderer are you using?
 
pothineni rajesh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic