I am trying to select ANY component in a JTree with a single click always.
Currently, I can only do this on first time JTree comes up, or if its the first (leftmost)
component in a node.
The test program below has 2 nodes in a JTree, each with a JTextField in the
leftmost position & a JCheckBox in the rightmost position. So the first time I
can select a JCheckBox with a single click, but then I need to use 2 clicks.
I tried putting a mouse listener on the JCheckBox & then in the mouse listener's
mouseEntered() method, doing a requestFocusInWindow() on that JCheckBox.
According to print statements, mouseEntered() was never called.
The mousePressed() method was called per prints, but a requestFocusInWindow()
did not work there (still took 2 clicks). I also tried in mousePressed() method:
DefaultKeyboardFocusManager dkf = new DefaultKeyboardFocusManager();
--- thinking this would clear the focus to be like what it is when the tree is
1st brought up; but it still did not work to allow single click selection of the
Any help is much appreciated!
Here is my code:
Joined: Feb 07, 2011
So, no hints?
Does anyone have a suggestion on another forum
that might be good to post this in?