📄 simplepanel.java
字号:
import java.awt.*;
import javax.swing.*;
public class SimplePanel extends JPanel {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new SimplePanel());
f.setSize(400, 300);
f.setVisible(true);
}
public SimplePanel() {
super();
GridBagConstraints constraints = new GridBagConstraints();
GridBagLayout layout = new GridBagLayout();
setLayout(layout);
constraints.anchor = GridBagConstraints.WEST;
constraints.gridy = 0;
JLabel label = new JLabel("First name:");
add(label, constraints);
JTextField tf = new JTextField(8);
add(tf, constraints);
label = new JLabel("Last name:");
add(label, constraints);
tf = new JTextField(8);
add(tf, constraints);
constraints.gridy = 1;
label = new JLabel("Address:");
add(label, constraints);
tf = new JTextField(10);
add(tf, constraints);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -