java 如何在使用 Tab 键时选择 JTextField 中的文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1312422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to select text in JTextField while tabbing
提问by Lewis Jubb
I have a JDialogwith a series of JTextFields on it I would like the text each to be selected when I tab to it.
我有一个JDialog带有一系列JTextFields 我希望在我点击它时选择每个文本。
回答by thedude19
This exact question has been asked and answered, check it out here.
已经提出并回答了这个确切的问题,请在此处查看。
Short version: Add a focus listener to your text components and select all on focus, using SwingUtilities.invokeLater to ensure all pending AWT events have been processed.
简短版本:向文本组件添加焦点侦听器并选择所有焦点,使用 SwingUtilities.invokeLater 确保已处理所有挂起的 AWT 事件。
回答by Aaron Digulla
Call selectAll()in the focusGained()of the FocusListener
通话selectAll()中focusGained()的FocusListener

