布局管理器容器内可以存放各种组件,而组件的位置和大小是由容器内的布局管理器来决定的。在AWT中为我们提供了以下5种布局管理器:① FlowLayout 流式布局管理器② BorderLayout 边界布局管理器③ GridLayout 网格布局 ...
布局管理器
容器内可以存放各种组件,而组件的位置和大小是由容器内的布局管理器来决定的。在AWT中为我们提供了以下5种布局管理器:
① FlowLayout 流式布局管理器
② BorderLayout 边界布局管理器
③ GridLayout 网格布局管理器
④ CradLayout 卡片布局管理器
⑤ GridBagLayout 网格包布局管理器
容器中组件的布局通常由布局管理器控制。每个Container(比如一个Panel或一个Frame)都有一个与他相关的缺省布局管理器,Panel容器默认的是FlowLayout,Frame容器默认的是BorderLayout,我们可以通过调用setLayout()来改变布局管理器;
可以通过设置空布局管理器,来控制组件的大小金和位置。可以调用setLayout(null)。
在设置空布局管理器后,必须对所有的组件调用setLocation(),setSize()或setBounds(),将它们定位在容器中。
流式布局管理器
1 class MyFrame3 extends Frame { 2 public MyFrame3(String title) { 3 super(title); 4 } 5 6 public void init() { 7 FlowLayout layout=new FlowLayout(FlowLayout.LEFT);//设置左对齐 8 this.setLayout(layout); 9 this.setBackground(Color.CYAN);10 this.add(new Button("btn1"));11 this.add(new Button("btn2"));12 this.add(new Button("btn3"));13 this.add(new Button("btn4"));14 this.add(new Button("btn5"));15 this.add(new Button("btn6"));16 this.add(new Button("btn7"));17 this.add(new Button("btn8"));18 this.setSize(300, 300);19 this.setVisible(true);20 }21 }
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:AWT布局管理器
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。