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.
This is not the same as input focus; it’s just that the button should be the default button of the dialog.
Get the
JRootPaneusinggetRootPane()on your dialog/frame/window and usesetDefaultButtonon 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.