📄 flowlayouttest.java
字号:
//FlowLayoutTest.java
import java.awt.*;
import javax.swing.*;
public class FlowLayoutTest extends JFrame {
private JLabel lblPrompt = null;
private JTextField txtInput = null;
private JButton btnOK = null;
public FlowLayoutTest() {
super("FlowLayout Test");
//设置当前容器的布局方式为FlowLayout
this.getContentPane().setLayout(new FlowLayout(FlowLayout.LEADING));
lblPrompt = new JLabel("请输入你的姓名:");
txtInput = new JTextField(10);
btnOK = new JButton("OK");
//依次加入三个组件(顺序:从左到右,从上到下)
this.getContentPane().add(lblPrompt);
this.getContentPane().add(txtInput);
this.getContentPane().add(btnOK);
}
public static void main(String[]args) {
FlowLayoutTest flt = new FlowLayoutTest();
flt.setSize(400,100);
flt.setDefaultCloseOperation(EXIT_ON_CLOSE);
flt.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -