JTextField开始无输入焦点

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();
		}
	}
}

你可能感兴趣的:(java,swing,Go)