javaswingjscrollpanejtextareajeditorpane

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.


Solution

  • 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.