📄 boxlayoutdemo.java
字号:
// 例6.4.5 BoxLayoutDemo.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class BoxLayoutDemo
{
private JFrame jframe;
private JPanel jpl;
public BoxLayoutDemo()
{
jframe = new JFrame("BoxLayout演示窗口");
Container c = jframe.getContentPane();
jpl = new Jpanel();
c.add(jpl);
jframe.setSize(200,150);
jframe.setVisible(true);
jframe.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public static void main(String[] args)
{
new BoxLayoutDemo();
}
}
class Jpanel extends JPanel
{
JButton jb1,jb2,jb3,jb4;
Jpanel()
{
// 指定布局管理器为BoxLayout,其中this表示当前面板对象
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
jb1 = new JButton("按钮1");
jb2 = new JButton("按钮2");
jb3 = new JButton("按钮3");
jb4 = new JButton("按钮4");
add(jb1);add(jb2);add(jb3);add(jb4);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -