更改所选项目

huangapple go评论74阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年9月11日 06:24:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63838423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定