This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to select JButton? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to select JButton?" Watch "How to select JButton?" New topic

How to select JButton?

Milan Djukic

Joined: Feb 14, 2011
Posts: 27
How can i programmatically select button? Like JOptionPane.showOptionDialog(......,Object initialValue) .
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2090
Post your SSCCE that demonstrates the problem.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36478
Why would you want to select a button programmatically? Have you been through the Java™ Tutorials? This section might help.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19541

I think that requestFocus or requestFocusInWindow should do the trick. You may have to use EventQueue.invokeLater to call this, even if you call it from the EDT itself, because I think a delayed event will be necessary.

How To Ask Questions How To Answer Questions
It is sorta covered in the JavaRanch Style Guide.
subject: How to select JButton?
Similar Threads
How to select a folder
How to select a tray in java print service?
Who attempted Part 1 please answer
Selecting the directory
Selecting JTree node