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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checkbox not working in JTable.

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I am working on swing application(displaying checkbox in Jtable) and facing this problem..

As an ouput MiscPanel is displaying a list of data in table format.
Column 0 = displaying checkbox
Column 1 = displaying types(string)

1) Onclicking checkboxes, ideally checkbox should selected. But nothing is happening.
2) On selecting on the types column cell, if I update the value and click on another cell then the
value on previously modified cell is unchanged and still displaying the default value in cell.

Did i need to any kind of listeners to table/tablemodel?
any other interface needs to be implemented?

Please let me know in detail how to resolve this.


//Code snippet

public JPanel getMiscPanel()
{
private String [] pNames = {"select","type"};
myMmodel= new MYTablemodel();
table = new JTable(myMmodel);
}

protected class MYTablemodel extends AbstractTableModel
{
Vector productDetails ;
MYTablemodel(){
productDetails = model.getProductDetails(); //model is storing all the data.
}
public Object getValueAt(int rowIndex, int columnIndex)
{
if (productDetails.size()>0)
{
Hashtable ht = (Hashtable) productDetails.get(rowIndex);
String str = "" ;
if(ht.containsKey(pNames[columnIndex]) && columnIndex!=0)
{
str = (String) ht.get(pNames[columnIndex]);
return str;
}else if(columnIndex==0){
return (Boolean)ht.get(pNames[columnIndex]);
}
}
return null;
}
public boolean isCellEditable(int row, int col)
{
return true;
}
public Class getColumnClass(int column)
{
if (column == 0) {
return Boolean.class;
}else{
return Object.class;
}
}
}

Thanks
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Let's keep this all in your original thread, shall we? Closing this one.

The problem is, you need to override setValueAt as well, and set the value for the boolean column. I warned you about this in the original thread already:

Originally posted by Rob Prime:
Also, this value should be stored somehow - otherwise the checked state will be forgotten.



And another line of that post is appropriate here:

Originally posted by Rob Prime:
Please Use Code Tags in the future.

 
Sharad
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Rob
Last thread was reagrding adding checkbox and this is for checkbox is not working.

I create an another thread with proper subject line..hope this is ok..

well your suggesstion for setValueAt() will come later..because after clicking on the checkbox it is not showing even the selected(right tick) icon.

even though i didnt click anywhere else..checkbox state is as it is...
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic