Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checkbox in TreeTable  RSS feed

 
Rehan Ahmad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a TreeTable using following example
http://java.sun.com/products/jfc/tsc/articles/bookmarks/#editableJTreeTable
Now i want to use Checkbox in TreeTable. I couldn't find any example on the net.
I tried the code from one of forum link as

public class CustomTreeTableModel extends AbstractTreeTableModel implements TreeTableModel
{
protected static String[] columnNames = {"Column 1", "Column 2"};
protected static Class[] columnTypes = {TreeTableModel.class, Boolean.class};
protected Object[] getChildren(Object node)
public int getColumnCount()
public String getColumnName(int column)
{
return columnNames[column];
}

public Class getColumnClass(int column)
{
return columnTypes[column];
}
public Object getValueAt(Object node, int column)
{
CustomNode cNode = (CustomNode)node;
switch(column)
{
case 0:
return node; // Remember to override the toString() method
case 1:
return cNode.isSelected(); // This will return a boolean value,
//which will be rendered as a checkbox in the table.
}
return null;
}
public Object getChild(Object parent, int index)
{
return getChildren(parent)[index];
}
public int getChildCount(Object parent)
{
Object[] children = getChildren(parent);
return (children == null) ? 0 : children.length;
}
public void setValueAt(Object aValue, Object node, int column)
{
if(column == 1)
{
((CustomNode)node).setSelected(new Boolean(aValue.toString()));
}
}
/* It is important that the column containing the tree nodes is editable.
Also if you are using checkboxes, then the second column should
also be editable in order to respond to user events.*/
public boolean isCellEditable(Object node, int column)
{
return super.isCellEditable(node, column) || column == 1;
}
}



..but still not able to get my checkbox working.Can someone help me
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!