JAVA 栈布局 JTEXTFIELD 获得光标

2024-12-17 08:18:44
推荐回答(1个)
回答1:

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.*;

public class Test extends JFrame {
JTextField txt=new JTextField (20);
JTextField txt2=new JTextField (10);

JPanel pa=new JPanel();
Test(){

pa.add(txt);
pa.add(txt2);

this.addWindowListener(new WindowAdapter(){
public void windowActivated(WindowEvent e) {
txt2.requestFocusInWindow();
}
});

this.add(pa);
this.setBounds(20, 20, 300, 200);
this.setVisible(true);

}
public static void main(String s[]){
new Test();
}

}