JButton Focus

I have a window with JTable at the bottom and split pane at the top. When the user is interacting with the application and fills out a form in a pop-up window, the application displays images and its corresponding data in the JTable.

I want the focus to be on the JButton that is next to the toolbar after the images and its data are displayed on the window.

I tried myButton.requestFocusInWindow() call, it doesn't do anything. Any ideas on how I can make the jbutton gain focus? TIA.

[506 byte] By [balachandrana] at [2007-10-3 2:57:53]
# 1
A component can only request focus when the GUI is visible.
camickra at 2007-7-14 20:47:15 > top of Java-index,Desktop,Core GUI APIs...
# 2
Try using FocusEvents,FocusEvent focusEvent = new FocusEvent(myButton, FocusEvent.FOCUS_GAINED);dispatchEvent(focusEvent);Cheers!
Roswella at 2007-7-14 20:47:15 > top of Java-index,Desktop,Core GUI APIs...
# 3

The button is visible and is enabled. I tried your code snippet. No luck. When I hit enter, the button does not have the focus, so I am not able to push the button (using keyboard only, no mouse is involved here.).

When I tab the JTable gets the focus. How can I make the button gain the focus at least when I tab once? Thanks for the tip.

balachandrana at 2007-7-14 20:47:15 > top of Java-index,Desktop,Core GUI APIs...
# 4

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-14 20:47:15 > top of Java-index,Desktop,Core GUI APIs...