Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JCheckBox in JTable Rendering problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> may be this is becoz of renderining problem..

who knows?

the answer is in the code
 
Sheriff
Posts: 22649
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
 
Poop goes in a willow feeder. Wipe with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic