Access to the checkbox of each Ode from a Jtree

Asked

Viewed 68 times

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?

  • Yes, it’s the same!

  • 1

    Well, you need to select from the Selectionmodel and not direct from jTree1. So: checkTreeManager.getSelectionModel().addSelectionPaths(checkedPaths);

  • And I place this command after jtree is fed back?

  • This command you replace with your second command in the question...

  • 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

  • @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

  • 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.

  • 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

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.