Single selection in a JTreeTag(s): Swing

myJTree.getSelectionModel().
   setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
Also you may want to disable the CTRL-A key which select the entire tree.
[JDK1.2]
KeyStroke ks = KeyStroke.getKeyStroke("ctrl A");
tree.unregisterKeyboardAction(ks);

[JDK1.3+]
KeyStroke ks = KeyStroke.getKeyStroke("ctrl A");
tree.getInputMap().put(ks, "none");



If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2012
[ home ]