Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic