- 论坛徽章:
- 0
|
swing中的焦点设置问题!
- import java.awt.BorderLayout;
- import javax.swing.JFrame;
- import javax.swing.JRadioButton;
- import javax.swing.JTextField;
- public class GrabFocusTest {
- public static void main(String[] args) {
- JFrame jf = new JFrame("Grab Focus Test");
- //Radio Button
- JRadioButton jrb = new JRadioButton("Radio 1");
- jf.getContentPane().add(jrb, BorderLayout.NORTH);
- //TextField
- JTextField jtf = new JTextField();
- jf.getContentPane().add(jtf, BorderLayout.CENTER);
- //main loop
- jf.setSize(100, 250);
- jf.show();
- //Move focus to text field, this operation must be after
- //the JFrame has been shown.
- jtf.grabFocus();
- jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
复制代码 |
|