I am building a treetable
using JXTreeTabble
and I want to disable/able menu
items depending on the selected value. So, I tried to put this code in my table model
:
public Object getValueAt(int index) {
if (index >= 0 && index < root.getSize()){
return root.get(index);
}
return null;
}
The problem
The above only works if the contents of the table
are not expanded. Because the index
of the selected row
might be larger than the size
of the table model
(model can have two items and row can have 10 when everything is expanded). Also, the object type
of the parent
is different from the children
(think of a book with chapters as it children).
What would you suggest as a way to do the above correctly?
assuming index
is your row number, try the following to get hold of the node object:
TreePath path = treetable.getPathForRow(index);
Object node = path.getLastPathComponent();
where treetable
would be a pointer to the table using this table model.
at JXTreeTable you could access value based on row and nodeClass from your treeTable. example:
int row=treeTable.getSelectedRow();
//get value from column
Object object= treeTable.getValueAt(row, yourColumn);
TreePath path= treeTable.getPathForRow(row);
Object o= path.getLastPathComponent();
Class<? extends Object> entity=o.getClass();
the result you would get an Class from the object, you could parse the object to get the value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With