Holis
Holis

Reputation: 175

Change the selected item

I have a JEditorPane and when I press ctr + space it makes visible a JScrollPane but because the editor pane is still selected is there any way to set the selected Item to be another?

(Selected is when you press a JTextArea and you can edit it so is selected the text area.)

Like I want to when I press ctr + space it appears the scroll pane and it selected so I just need to press an arrow to scroll.

Upvotes: 1

Views: 111

Answers (1)

leo277
leo277

Reputation: 439

You need to call requestFocus() on the JComponent you want "selected".

Edit: From the documentation for JComponent#requestFocus:

Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of requestFocusInWindow(boolean).

So maybe give requestFocusInWindow() a try as well.

Upvotes: 1

Related Questions