[英]JTextField in JDialog box is not getting focused
I am making a save Dialog box using Swing GUI builder. 我正在使用Swing GUI构建器制作一个保存对话框。 I have used a
JDialog
box for this. 我为此使用了一个
JDialog
框。 I have some buttons and a JTextField
(for the filename) in the dialog box. 我在对话框中有一些按钮和一个
JTextField
(用于文件名)。
The problem is that when I run the program, the text field is not getting focused when clicked and hence I cannot write into it. 问题是,当我运行该程序时,单击该文本字段时不会使其焦点集中,因此无法对其进行写入。 I even tried using
requestFocus()
but it doesn't help. 我什至尝试使用
requestFocus()
但没有帮助。 I do not understand why this is happening and how to resolve this. 我不明白为什么会这样以及如何解决。
Here is what I have done so far: 到目前为止,这是我所做的:
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.requestFocus();
}
How would I resolve this? 我该如何解决?
The jTextField1ActionPerformed will be called when an action is preformed on the jTextField. 在jTextField上执行操作时,将调用jTextField1ActionPerformed。 Have you tried calling jTextField1.requestFocus method after you call JFrame.setVisible?
调用JFrame.setVisible后是否尝试调用jTextField1.requestFocus方法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.