I have a JTree
and an awt.Canvas
. When i select multiple objects from within the Canvas
into the objList
, I want all the
You are looking for the TreeSelectionModel
of the JTree
(use the getter). Use the TreeSelectionModel#setSelectionPaths for multiple paths. Now you are only setting one node selected due to your tree.setSelectionPath(tpath);
call. The TreeSelectionModel
also has methods to add/remove to an existing selection ,... (basically everything you might need in the future).
An interesting method for the expansion is the JTree#setExpandsSelectedPaths method which allows to configure the JTree
to automatically expand selected paths. If you want to manage this manually, you can use the JTree#setExpandedState method