0
How can I access the checkbox of each Ode of a JTree
?
TreePath[] checkedPaths = checkTreeManager.getSelectionModel().getSelectionPaths();
The previous code returns me all the selected paths. When I return to mine JTree
after losing focus, I would like these paths to be selected.
I tried using the following command:
jTree1.addSelectionPaths(checkedPaths);
The point is that selects me the line of the nodes selected and does not check me in the associated checkbox as you would like.
Does anyone know how I can fix this?
In the second command, when adding selections, the checkedPaths object is the same as the first command?
– Franchesco
Yes, it’s the same!
– Hugo Machado
Well, you need to select from the Selectionmodel and not direct from jTree1. So:
checkTreeManager.getSelectionModel().addSelectionPaths(checkedPaths);
– Franchesco
And I place this command after jtree is fed back?
– Hugo Machado
This command you replace with your second command in the question...
– Franchesco
If you put as you told me, do not select as I want, maybe by my mistake here in the code, however if you do: 'checkTreeManager.getSelectionModel(). addSelectionPath(jTree1.getPathForRow(4));' selects it right as I want, so I’ll save the indexes of the selected paths and then do it :D
– Hugo Machado
@Earendul already got to select but I’m having trouble selecting the Child nodes. Ex: root->A->A1, if the path is this and I select A1, it is not selected :s
– Hugo Machado
If A has only this child, then it will be selected A. But if A has no siblings, it will select only root. That is, when all the children of a node are selected, it returns only their father. For example, if it returns A as the last selected node, it means that all children of A are also selected.
– Franchesco
Right and in the selection mode this happens, the question is that I have: Root->A->A1, A2 (where A1 and A2 are children of A) if my selection is A1, it does not select me this path. I think I know where my problem is that I’m going through jtree like this: for(int i = 0; i<jtree.getRowCount();i++) and supposedly this rowCount I don’t think it counts A1 and A2, it only counts Root-> A , B , C
– Hugo Machado