英文:
Change the selected item
问题
我有一个JEditorPane
,当我按下ctrl + space时,会显示一个JScrollPane
,但因为编辑窗格仍然被选中,是否有办法将选定的项目设置为另一个项目?
(所选是指当您按下JTextArea
并且可以编辑它时,所以文本区域被选中。)
就像我想,当我按下ctrl + space时,它会出现滚动窗格,并且会被选中,所以我只需要按箭头键即可滚动。
英文:
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.
答案1
得分: 1
你需要在想要“选定”的 JComponent 上调用 requestFocus()。
编辑:根据 JComponent#requestFocus 的文档:
> 注意,不推荐使用此方法,因为其行为因平台而异。相反,我们建议使用 requestFocusInWindow(boolean)。
所以也可以尝试使用 requestFocusInWindow()。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论