ChuckH
ChuckH

Reputation: 65

Make JButton Look Like It Has Input Focus

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

Answers (1)

Joey
Joey

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

Related Questions