[英]How to set a JTextArea to be clicked on by default in a JFrame?
当我启动我的程序时,我希望能够默认输入 JTextArea。 现在,我必须先单击 JTextArea,然后才能开始输入。
尝试调用requestFocus();
在文本区域
如果这没有帮助,请向框架添加一个侦听器并在接收到窗口打开事件时请求焦点。
IE
JFrame frame = new JFrame();
frame.setSize(300, 300);
JTextArea textArea = new JTextArea();
frame.add(textArea);
frame.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent e) {
textArea.requestFocus();
}
});
textArea.requestFocus();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.