AsWing布局管理——FlowLayout
[原文] http://harryxu.cn/blog/?p=113 [原文中有flash效果演示]
FlowLayout使容器内的组件按从左到右的顺序排列,每个组件都按最合适的大小显示,直到这一行放不下后,会换到下一行,类似于文本书写的形式。
Actionscript:
package{import flash.
display.
Sprite;
import flash.
display.
StageScaleMode;
import org.aswing.JFrame;
import org.aswing.JButton;
import org.aswing.FlowLayout;
import org.aswing.JTextArea;
import org.aswing.JLabel;
import org.aswing.AsWingManager;
public class FlowLayoutTest extends Sprite
{
public function FlowLayoutTest()
{
AsWingManager.setRoot(this);
var frame:JFrame = new JFrame(this, "FlowLayoutTest");
frame.getContentPane().setLayout(new FlowLayout());
var label1:JLabel = new JLabel("JLabel");
var button1:JButton = new JButton("btn1");
var button2:JButton = new JButton("buttttttton2");
var button3:JButton = new JButton("button");
var text1:JTextArea = new JTextArea("改变窗口的宽度查看效果");
frame.getContentPane().appendAll(label1, button1, button2, button3, text1);
frame.show();
frame.setSizeWH(160, 280);
stage.scaleMode = StageScaleMode.NO_SCALE;
}
}
}
AsWing布局管理——EmptyLayout
[原文] http://harryxu.cn/blog/?p=112
EmptyLayout是对LayoutManager接口的空实现,是其他布局管理的基类,如果要对容器内组件进行绝对定位和大小控制,可以使用EmptyLayout
Actionscript:
package{import flash.
display.
Sprite;
import flash.
display.
StageScaleMode;
import org.aswing.AsWingManager;
import org.aswing.JFrame;
import org.aswing.JButton;
import org.aswing.EmptyLayout;
public class EmptyLayoutTest extends Sprite
{
public function EmptyLayoutTest()
{
AsWingManager.setRoot(this);
var frame:JFrame = new JFrame(this, "EmptyLayoutTest");
frame.getContentPane().setLayout(new EmptyLayout());
var button1:JButton = new JButton("button1");
button1.setSizeWH(80, 30);
button1.setLocationXY(50, 20);
frame.getContentPane().append(button1);
var button2:JButton = new JButton("button2");
button2.setSizeWH(200,150);
button2.setLocationXY(60, 70);
frame.getContentPane().append(button2);
frame.show();
frame.setSizeWH(350, 280);
this.stage.scaleMode = StageScaleMode.NO_SCALE;
}
}
}
AsWing布局管理——BorderLayout
[原文] http://harryxu.cn/blog/?p=111
感觉学AsWing应该先熟悉他的布局管理,才能灵活运用,组合出各种界面
从现在就记录一下平时学到的布局管理器的使用方法,还请大大们指教 :[smile]:
BorderLayout: 个人感觉边框布局是一种使用起来比较简单的布局方式,他将容器分为5各部分 东南西北中,每一个区域中可以容纳一个组件,使用的时候也是通过BorderLayout中的5个方位常量(NORTH, WEST等)来确定组件所在的位置。
Actionscript:
package {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import org.aswing.AsWingManager;
import org.aswing.JFrame;
import org.aswing.JButton;
import org.aswing.BorderLayout;
public class BorderLayoutTest extends Sprite
{
public function BorderLayoutTest():void
{
AsWingManager.setRoot(this);
var frame:JFrame = new JFrame(this, "BorderLayout");
// BorderLayout 构造函数的2个参数分别为 hgap 和 vgap
// 用于设定组件之间的水平间隙和垂直间隙
frame.getContentPane().setLayout(new BorderLayout(5, 5));
var button1:JButton = new JButton("Button North");
frame.getContentPane().append(button1, BorderLayout.NORTH);
var button2:JButton = new JButton("Button West");
frame.getContentPane().append(button2, BorderLayout.WEST);
var button3:JButton = new JButton("Button South");
frame.getContentPane().append(button3, BorderLayout.SOUTH);
var button4:JButton = new JButton("Button East");
frame.getContentPane().append(button4, BorderLayout.EAST);
var button5:JButton = new JButton("Button Center");
frame.getContentPane().append(button5, BorderLayout.CENTER);
frame.show();
frame.setSizeWH(350, 280);
this.stage.scaleMode = StageScaleMode.NO_SCALE;
}
}
}