Reputation: 65
Is there any way to make a JButton look like it has the input focus when it doesn't?
I am creating a search window that has a text area for the input and a 'Find Next' button to start the search. I want the 'Find Next' button to appear to have the focus even though keyboard input is going to the text area. The idea is notify the user that pressing <Enter>
will start the search, similar to applications like Microsoft Word.
I know that I can paint the button myself, but I'm looking for an easier way.
Upvotes: 2
Views: 172
Reputation: 354854
This is not the same as input focus; it's just that the button should be the default button of the dialog.
Get the JRootPane
using getRootPane()
on your dialog/frame/window and use setDefaultButton
on that instead.
L&Fs might draw the default button even differently than one having input focus, so a user might be quite confused if there are two apparent controls having focus.
Upvotes: 7