Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Bruce Harden
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, no hints?

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

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic