使 JButton 看起来像有输入焦点
有没有办法让 JButton 看起来像有输入焦点,而实际上没有?
我正在创建一个搜索窗口,其中有一个用于输入的文本区域和一个用于开始搜索的“查找下一个”按钮。我希望“查找下一个”按钮看起来具有焦点,即使键盘输入将转到文本区域也是如此。这个想法是通知用户按
将开始搜索,类似于 Microsoft Word 等应用程序。
我知道我可以自己绘制按钮,但我正在寻找一种更简单的方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与输入焦点不同;只是该按钮应该是对话框的默认按钮。
获取
JRootPane
使用getRootPane()
在对话框/框架/窗口上并使用setDefaultButton
代替。L&F 绘制的默认按钮甚至可能与具有输入焦点的按钮不同,因此如果有两个明显的控件具有焦点,用户可能会感到非常困惑。
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
usinggetRootPane()
on your dialog/frame/window and usesetDefaultButton
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.