import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Test {
private JFrame jfr;
private JTextField jtf;
public static void main(String[] args) {
new Test().go();
}
public void go() {
jfr = new JFrame();
jtf = new JTextField();
jfr.add(jtf);
jfr.setSize(200, 100);
jtf.setFocusable(false);
jtf.addMouseListener(new MyMouseAdapter());
jfr.setVisible(true);
jfr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MyMouseAdapter extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
jtf.setFocusable(true);
jtf.requestFocus();
}
}
}
JTextField开始无输入焦点
最新推荐文章于 2024-07-11 08:12:25 发布