aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTree:  Want to use single click to select any component in node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree:  Want to use single click to select any component in node" Watch "JTree:  Want to use single click to select any component in node" New topic
Author

JTree: Want to use single click to select any component in node

Bruce Harden
Greenhorn

Joined: Feb 07, 2011
Posts: 4
Hi:

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();
dkf.clearGlobalFocusOwner();

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

Any help is much appreciated!


Here is my code:

Bruce Harden
Greenhorn

Joined: Feb 07, 2011
Posts: 4
So, no hints?

Does anyone have a suggestion on another forum
that might be good to post this in?

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree: Want to use single click to select any component in node