RowLayout行列式布局

总结:七个属性

		RowLayout layout=new RowLayout();
		//(1)设置填充方式type
		layout.type=SWT.HORIZONTAL;//设置水平填充
		//(2)设置补白和控件的间隙
		layout.marginLeft=10;//左补白
		layout.marginTop=10;//上补白
		layout.marginRight=10;//右补白
		layout.marginBottom=10;//下补白
		layout.spacing=5;//控件之间的空隙		
		//(3)设置可以折行显示
		//layout.wrap=false;
		layout.wrap=true;//默认可以折行,即默认为true				
		//(4)设置自动设置空间大小pack()
		//layout.pack=false;//默认为true
		layout.pack=true;		
		//(5)判断是否充满整行,默认不是充满整行justify
		//再设置了layout.justify=true之后,再去设置layout.spacing属性,
		//如果此时的窗口足够大,该属性(spacing)将不起作用
		layout.justify=true;//默认为false
		//(6)设置控件是否等高(当水平填充时候);设置控件是否等宽(当垂直填充的时候)
		//如果设置成这样,则布局管理器试图使所有的按钮同等高度(同等宽度)。
		layout.fill=true;		

		shell.setLayout(layout);			

		//(7)设置控件的大小RowData
		Button bt=new Button(shell,SWT.PUSH);
		bt.setText("按钮1");
		//设置按钮控件的宽为100像素,高为30像素
		//bt.setLayoutData(layoutData);
		bt.setLayoutData(new RowData(100,30));

1.左上右下的设置留白,并设置控件之间的间隙

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class C{
	public static void main(String[] args){
		Display display=new Display();
		Shell shell=new Shell(display,SWT.SHELL_TRIM);
		shell.setText("RowLayout行列式布局");
		
		RowLayout layout=new RowLayout();
		layout.type=SWT.HORIZONTAL;//设置水平填充
		layout.marginLeft=10;//左补白
		layout.marginTop=10;//上补白
		layout.marginRight=10;//右补白
		layout.marginBottom=10;//下补白
		layout.spacing=5;//控件之间的空隙
		shell.setLayout(layout);	
		
		new Button(shell,SWT.PUSH).setText("按钮1");
		new Button(shell,SWT.PUSH).setText("按钮2");
		new Button(shell,SWT.PUSH).setText("按钮3");
		new Button(shell,SWT.PUSH).setText("按钮3");
		
		//打开窗口,进行窗口的显示
		shell.setSize(300,100);
		//shell.pack();
		shell.open();
		while(!shell.isDisposed()){
			//当窗口没有被释放的时候
			if(!display.readAndDispatch()){
				display.sleep();
			}		
		}
		display.dispose();
	}
}

2.设置是否可以折行,默认可以折行。layout.wrap=true;(默认)

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class D{
	public static void main(String[] args){
		Display display=new Display();
		Shell shell=new Shell(display,SWT.SHELL_TRIM);
		shell.setText("RowLayout行列式布局");
		
		RowLayout layout=new RowLayout();
		layout.type=SWT.HORIZONTAL;//设置水平填充
		layout.marginLeft=10;//左补白
		layout.marginTop=10;//上补白
		layout.marginRight=10;//右补白
		layout.marginBottom=10;//下补白
		layout.spacing=5;//控件之间的空隙
		
		//layout.wrap=true;//设置可以折行显示,默认可以折行,即默认为true
		layout.wrap=false;
		
		shell.setLayout(layout);	
		
		new Button(shell,SWT.PUSH).setText("按钮1");
		new Button(shell,SWT.PUSH).setText("按钮2");
		new Button(shell,SWT.PUSH).setText("按钮3");
		new Button(shell,SWT.PUSH).setText("按钮4");
		new Button(shell,SWT.PUSH).setText("按钮5");
		new Button(shell,SWT.PUSH).setText("按钮6");
		new Button(shell,SWT.PUSH).setText("按钮7");
		new Button(shell,SWT.PUSH).setText("按钮8");
		
		//打开窗口,进行窗口的显示
		shell.setSize(300,120);
		//shell.pack();
		shell.open();
		while(!shell.isDisposed()){
			//当窗口没有被释放的时候
			if(!display.readAndDispatch()){
				display.sleep();
			}		
		}
		display.dispose();
	}
}

3.利用RowData设置其中控件的大小。

如设置按钮控件的长为100,宽为30。button.setLayoutData(new RowData(100,30));

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class E{
	public static void main(String[] args){
		Display display=new Display();
		Shell shell=new Shell(display,SWT.SHELL_TRIM);
		shell.setText("RowLayout行列式布局");
		
		RowLayout layout=new RowLayout();
		//设置填充方式type
		layout.type=SWT.HORIZONTAL;//设置水平填充
		//设置补白和控件的间隙
		layout.marginLeft=10;//左补白
		layout.marginTop=10;//上补白
		layout.marginRight=10;//右补白
		layout.marginBottom=10;//下补白
		layout.spacing=5;//控件之间的空隙
		
		//设置可以折行显示
		layout.wrap=true;//默认可以折行,即默认为true
		//layout.wrap=false;
		
		//设置自动设置空间大小pack()
		//layout.pack=false;//默认为true
		layout.pack=true;
		
		//判断是否充满整行,默认不是充满整行justify
		layout.justify=true;//默认为false
		//再设置了layout.justify=true之后,再去设置layout.spacing属性,
		//如果此时的窗口足够大,该属性(spacing)将不起作用
		
		shell.setLayout(layout);	
		
		//设置控件的大小RowData
		Button bt=new Button(shell,SWT.PUSH);
		bt.setText("按钮1");
		//设置按钮控件的宽为100像素,高为30像素
		//bt.setLayoutData(layoutData);
		bt.setLayoutData(new RowData(100,30));
		
		new Button(shell,SWT.PUSH).setText("按钮2");
		new Button(shell,SWT.PUSH).setText("按钮3");
		new Button(shell,SWT.PUSH).setText("按钮4");
		new Button(shell,SWT.PUSH).setText("按钮5");
		
		//打开窗口,进行窗口的显示
		shell.setSize(300,100);
		//shell.pack();
		shell.open();
		while(!shell.isDisposed()){
			//当窗口没有被释放的时候
			if(!display.readAndDispatch()){
				display.sleep();
			}		
		}
		display.dispose();
	}
}

4.设置控件是否同等高度(当水平填充时);设置控件是否同等宽度(当垂直填充时)。layout.fill=false;(默认)

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class E{
	public static void main(String[] args){
		Display display=new Display();
		Shell shell=new Shell(display,SWT.SHELL_TRIM);
		shell.setText("RowLayout行列式布局");
		
		RowLayout layout=new RowLayout();
		//(1)设置填充方式type
		layout.type=SWT.HORIZONTAL;//设置水平填充
		//(2)设置补白和控件的间隙
		layout.marginLeft=10;//左补白
		layout.marginTop=10;//上补白
		layout.marginRight=10;//右补白
		layout.marginBottom=10;//下补白
		layout.spacing=5;//控件之间的空隙
		
		//(3)设置可以折行显示
		layout.wrap=true;//默认可以折行,即默认为true
		//layout.wrap=false;
		
		//(4)设置自动设置空间大小pack()
		//layout.pack=false;//默认为true
		layout.pack=true;
		
		//(5)判断是否充满整行,默认不是充满整行justify
		layout.justify=true;//默认为false
		//再设置了layout.justify=true之后,再去设置layout.spacing属性,
		//如果此时的窗口足够大,该属性(spacing)将不起作用
		
		//(6)设置控件是否等高(当水平填充时候);设置控件是否等宽(当垂直填充的时候)
		layout.fill=true;
		//如果设置成这样,则布局管理器试图使所有的按钮同等高度(同等宽度)。

		shell.setLayout(layout);	
		
		//(7)设置控件的大小RowData
		Button bt=new Button(shell,SWT.PUSH);
		bt.setText("按钮1");
		//设置按钮控件的宽为100像素,高为30像素
		//bt.setLayoutData(layoutData);
		bt.setLayoutData(new RowData(100,30));
		
		new Button(shell,SWT.PUSH).setText("按钮2");
		new Button(shell,SWT.PUSH).setText("按钮3");
		new Button(shell,SWT.PUSH).setText("按钮4");
		new Button(shell,SWT.PUSH).setText("按钮5");
		
		//打开窗口,进行窗口的显示
		shell.setSize(300,120);
		//shell.pack();
		shell.open();
		while(!shell.isDisposed()){
			//当窗口没有被释放的时候
			if(!display.readAndDispatch()){
				display.sleep();
			}		
		}
		display.dispose();
	}
}

 

 

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值