[英]How to set a JTextArea to be clicked on by default in a JFrame?
When I launch my program, I want to be able to type in the JTextArea by default.当我启动我的程序时,我希望能够默认输入 JTextArea。 Right now, I have to click on the JTextArea before I can start typing in it.现在,我必须先单击 JTextArea,然后才能开始输入。
Try invoking requestFocus();
尝试调用requestFocus();
on the text area在文本区域
If that doesn't help, add a listener to the frame and request the focus upon receiving the window opened event.如果这没有帮助,请向框架添加一个侦听器并在接收到窗口打开事件时请求焦点。
ie 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.