It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Checkbox not working in JTable. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply locked New topic

Checkbox not working in JTable.


Joined: Aug 04, 2008
Posts: 10
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 ;
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;
return Object.class;

Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

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.

How To Ask Questions How To Answer Questions

Joined: Aug 04, 2008
Posts: 10
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 agree. Here's the link:
subject: Checkbox not working in JTable.
jQuery in Action, 3rd edition