GridLayout网格式布局
1.设置网格的列数。gridLayout.numColumns=3;//设置网格的列数为3,默认是1
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class A{public static void main(String[] args){Display display=new Display();Shell shell=new Shell(display);shell.setText("GridLayout网格式布局");//(1)设置网格的列数:numColumns=1(默认)GridLayout gridLayout=new GridLayout();gridLayout.numColumns=3;//设置3列网格shell.setLayout(gridLayout);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("Button4");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();}
}
2.设置网格等宽。makeColumnsEqualWidth属性;gridLayout.makeColumnsEqualWidth=true;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class A{public static void main(String[] args){Display display=new Display();Shell shell=new Shell(display);shell.setText("GridLayout网格式布局");//(1)设置网格的列数:numColumns=1(默认)GridLayout gridLayout=new GridLayout();gridLayout.numColumns=3;//设置3列网格//(2)设置网格等宽:makeColumnsEqualWidth属性gridLayout.makeColumnsEqualWidth=true;shell.setLayout(gridLayout);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("Button4");new Button(shell,SWT.PUSH).setText("按钮5");new Button(shell,SWT.PUSH).setText("button666");//打开窗口,进行窗口的显示shell.setSize(300,120);//shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
3.设置补白与控件之间的间隙。verticalSpacing(垂直间隙)与horizontalSpacing(水平间隙)。
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class B{public static void main(String[] args){Display display=new Display();Shell shell=new Shell(display);shell.setText("GridLayout网格式布局");//(1)设置网格的列数:numColumns=1(默认)GridLayout gridLayout=new GridLayout();gridLayout.numColumns=3;//设置3列网格//(2)设置网格等宽:makeColumnsEqualWidth属性gridLayout.makeColumnsEqualWidth=true;//(3)设置补白与间隔//GridLayout也有marginLeft,marginTop,marginRight和marginBottom等属性。//不同的是,GridLayout将spacing间隔分为水平间隔horizontalSpacing和垂直间隔verticalSpacing,默认为5和像素的大小。gridLayout.verticalSpacing=15;gridLayout.horizontalSpacing=15;shell.setLayout(gridLayout);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("Button4");new Button(shell,SWT.PUSH).setText("按钮5");new Button(shell,SWT.PUSH).setText("button666");//打开窗口,进行窗口的显示shell.setSize(300,120);//shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
4.利用GridData的设置GridLayout布局中的某一控件。//不可以重用GridData对象。
每一个面板(Composite)对象中被GridLayout管理的控件必须有一个唯一的GridData对象。如果在设置布局的时候,一个GridLayout中的控件的GridData为null,就会为它创建一个唯一的GridData对象。
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);shell.setText("GridLayout网格式布局");//(1)设置网格的列数:numColumns=1(默认)GridLayout gridLayout=new GridLayout();gridLayout.numColumns=3;//设置3列网格//(2)设置网格等宽:makeColumnsEqualWidth属性gridLayout.makeColumnsEqualWidth=true;//(3)设置补白与间隔//GridLayout也有marginLeft,marginTop,marginRight和marginBottom等属性。//不同的是,GridLayout将spacing间隔分为水平间隔horizontalSpacing和垂直间隔verticalSpacing,默认为5和像素的大小。gridLayout.verticalSpacing=15;gridLayout.horizontalSpacing=15;//(4)使用GridData对象,它的作用是设置GridLayout布局中某一控件。//方法一:Button bt1=new Button(shell,SWT.PUSH);bt1.setText("bt1");//(4.1)创建GridDa对象GridData gridData=new GridData();//(4.2)设置水平填充方式充满单元格,功能:无此句,则文字有多少,按钮的长度就有多长。gridData.horizontalAlignment=GridData.FILL;//(4.3)设置水平抢占空间的方式,这句话暂时没有用//gridData.grabExcessHorizontalSpace=false;gridData.grabExcessHorizontalSpace=true; //(4.4)设置按钮的布局数据bt1.setLayoutData(gridData);//方法二:
// Button bt2=new Button(shell,SWT.PUSH);
// bt2.setText("bt2");
// bt2.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.GRAB_HORIZONTAL));shell.setLayout(gridLayout);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("Button4");new Button(shell,SWT.PUSH).setText("按钮5");new Button(shell,SWT.PUSH).setText("button666");//打开窗口,进行窗口的显示shell.setSize(300,120);//shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
5.控件左对齐与右对齐。为按钮设置GridData对象
gridData.horizontalAlignment=SWT.BEGINNING;//左对齐
gridData.horizontalAlignment=SWT.END;//右对齐
设置第5个按钮的左对齐与右对齐。
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);shell.setText("GridLayout网格式布局");//(1)设置网格的列数:numColumns=1(默认)GridLayout gridLayout=new GridLayout();gridLayout.numColumns=3;//设置3列网格//(2)设置网格等宽:makeColumnsEqualWidth属性gridLayout.makeColumnsEqualWidth=true;//(3)设置补白与间隔//GridLayout也有marginLeft,marginTop,marginRight和marginBottom等属性。//不同的是,GridLayout将spacing间隔分为水平间隔horizontalSpacing和垂直间隔verticalSpacing,默认为5和像素的大小。gridLayout.verticalSpacing=15;gridLayout.horizontalSpacing=15;//(4)使用GridData对象,它的作用是设置GridLayout布局中某一控件。//方法一:Button bt1=new Button(shell,SWT.PUSH);bt1.setText("bt1");//(4.1)创建GridDa对象GridData gridData=new GridData();//(4.2)设置水平填充方式充满单元格,功能:无此句,则文字有多少,按钮的长度就有多长。gridData.horizontalAlignment=GridData.FILL;//(4.3)设置水平抢占空间的方式,这句话暂时没有用//gridData.grabExcessHorizontalSpace=false;gridData.grabExcessHorizontalSpace=true; //(4.4)设置按钮的布局数据bt1.setLayoutData(gridData);//方法二:
// Button bt2=new Button(shell,SWT.PUSH);
// bt2.setText("bt2");
// bt2.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.GRAB_HORIZONTAL));shell.setLayout(gridLayout);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("Button4");Button bt5=new Button(shell,SWT.PUSH);bt5.setText("Button5");GridData gridData1=new GridData();//设置水平对齐的方式//gridData1.horizontalAlignment=SWT.BEGINNING;//左对齐gridData1.horizontalAlignment=SWT.END;//右对齐//为第5个按钮设置GridData对象,设置按钮的布局数据bt5.setLayoutData(gridData1);new Button(shell,SWT.PUSH).setText("button666");//打开窗口,进行窗口的显示shell.setSize(300,150);//shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
6.利用GridData设置缩进大小。horizontalIndent和verticalIndent属性。
GridData gridData=new GridData();
gridData.horizontalIndent=20;//设置缩进为20个像素大小
设置按钮2和按钮4水平缩进20个像素。
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class F{public static void main(String[] args){Display display=new Display();Shell shell=new Shell(display);shell.setText("GridLayout网格式布局");GridLayout gridLayout=new GridLayout();gridLayout.numColumns=3;//设置为3列shell.setLayout(gridLayout);//设置缩进大小horizontalIndent和verticalIndent属性GridData gridData=new GridData();gridData.horizontalIndent=20;//设置缩进为20个像素大小new Button(shell,SWT.PUSH).setText("按钮1");Button bt2=new Button(shell,SWT.NONE);bt2.setText("Button2");bt2.setLayoutData(gridData);new Button(shell,SWT.PUSH).setText("333333");Button bt4=new Button(shell,SWT.NONE);bt4.setText("Button4");bt4.setLayoutData(gridData);new Button(shell,SWT.PUSH).setText("55555");new Button(shell,SWT.PUSH).setText("6");//打开窗口,进行窗口的显示shell.setSize(300,200);//shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
7.设置单元格垂直横跨与水平横跨;单元格的水平填充与垂直填充。
gridData.verticalSpan=3;//垂直横跨3个单元格;
gridData.verticalAlignment=SWT.FILL;//垂直填充;
左图是按钮5水平横跨2个单元格,并且水平填充。按钮1垂直横跨3个单元格。
右图是按钮5水平横跨2个单元格,并且水平填充。按钮1垂直横跨3个单元格,并且垂直填充。
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class G{public static void main(String[] args){Display display=new Display();Shell shell=new Shell(display);shell.setText("GridLayout网格式布局");GridLayout gridLayout=new GridLayout();gridLayout.numColumns=3;//设置有三列,默认只有1列shell.setLayout(gridLayout); //设置单元格跨行和跨列显示。horizontalSpan和verticalSpan属性//horizontalSpan和verticalSpan属性可以设置单元格水平跨越和垂直跨越的单元格数量。GridData gridData=new GridData();gridData.horizontalSpan=2;//设置水平跨越2个单元格gridData.horizontalAlignment=SWT.FILL;//水平填充GridData gridData2=new GridData();gridData2.verticalSpan=3;gridData2.verticalAlignment=SWT.FILL;//垂直填充//设置按钮1垂直跨越2个单元格Button bt1=new Button(shell,SWT.NONE);bt1.setText("Button1");bt1.setLayoutData(gridData2);new Button(shell,SWT.PUSH).setText("按钮2");new Button(shell,SWT.PUSH).setText("333333");new Button(shell,SWT.PUSH).setText("Button4");//设置第5个按钮水平横跨2个单元格Button bt5=new Button(shell,SWT.NONE);bt5.setText("Button5");bt5.setLayoutData(gridData);new Button(shell,SWT.PUSH).setText("button666");//打开窗口,进行窗口的显示shell.setSize(300,200);//shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
8.设置水平抢占和垂直抢占的属性。默认不抢占。
gridData.grabExcessVeritcalSpace=true;//设置垂直抢占
gridData.grabExcessHorizontalSpace=true;//设置水平抢占
以上的所有图片按钮3均是既水平填充也是垂直填充。
第1幅图是既水平抢占又垂直抢占。(代码)
第2幅图是既不水平抢占,也不垂直抢占。
第3幅图是垂直抢占。
第4幅图是水平抢占。
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class G{public static void main(String[] args){Display display=new Display();Shell shell=new Shell(display);shell.setText("GridLayout网格式布局");GridLayout gridLayout=new GridLayout();gridLayout.numColumns=4;//设置有三列,默认只有1列shell.setLayout(gridLayout); //设置单元格控件的抢占方式:grabExcessHorizontalSpace和//grabExcessVerticalSpace属性。默认为false,即默认不抢占GridData gridData=new GridData();gridData.verticalSpan=2;//垂直横跨2个单元格gridData.verticalAlignment=SWT.FILL;//设置垂直填充//新加属性gridData.horizontalAlignment=SWT.FILL;//设置水平填充gridData.grabExcessVerticalSpace=true;//设置垂直抢占gridData.grabExcessHorizontalSpace=true;//设置水平抢占new Button(shell,SWT.PUSH).setText("Button1");new Button(shell,SWT.PUSH).setText("按钮2");Button bt3=new Button(shell,SWT.PUSH);bt3.setText("333333");bt3.setLayoutData(gridData);new Button(shell,SWT.PUSH).setText("Button4");new Button(shell,SWT.PUSH).setText("按钮5");new Button(shell,SWT.PUSH).setText("66");new Button(shell,SWT.PUSH).setText("Button7");new Button(shell,SWT.PUSH).setText("按钮8");new Button(shell,SWT.PUSH).setText("99");//打开窗口,进行窗口的显示shell.setSize(300,200);//shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
9.设置控件的大小。——最小高度和最小宽度属性。
设置按钮3的最小高度是100像素,最小宽度也是100像素。
//设置控件的大小。minimumWidth和minimumHeight属性。
//(1)设置最小宽度和高度。这两个属性仅当垂直抢占和水平抢占的时候才会生效。
//即grabExcessHorizontalSpace=true;与grabExcessVerticalSpace=true时候才生效。
//(2)设置了这两个最值属性后,即使窗口变小了,这个按钮3的大小仍然不改变。控件的大小不会随着窗口大小的改变而改变。
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class H{public static void main(String[] args){Display display=new Display();Shell shell=new Shell(display);shell.setText("i am a shell");GridLayout gridLayout=new GridLayout();gridLayout.numColumns=4;shell.setLayout(gridLayout);//设置控件的大小。minimumWidth和minimumHeight属性。//(1)设置最小宽度和高度。这两个属性仅当垂直抢占和水平抢占的时候才会生效。//即grabExcessHorizontalSpace=true;与grabExcessVerticalSpace=true时候才生效。//(2)设置了这两个最值属性后,即使窗口变小了,这个按钮3的大小仍然不改变。GridData gridData=new GridData();//最小高度和最小宽度出现的前提条件gridData.grabExcessHorizontalSpace=true;gridData.grabExcessVerticalSpace=true;gridData.minimumHeight=100;//最小的高度gridData.minimumWidth=100;//最小宽度new Button(shell,SWT.PUSH).setText("Button1");new Button(shell,SWT.PUSH).setText("按钮2");Button bt3=new Button(shell,SWT.PUSH);bt3.setText("3");bt3.setLayoutData(gridData);new Button(shell,SWT.PUSH).setText("Button4");new Button(shell,SWT.PUSH).setText("按钮5");new Button(shell,SWT.PUSH).setText("66");new Button(shell,SWT.PUSH).setText("Button7");new Button(shell,SWT.PUSH).setText("按钮8");new Button(shell,SWT.PUSH).setText("99");//打开窗口,进行窗口的显示//shell.setSize(400,400);shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
10.设置控件的大小。——widthHint和heightHint属性(宽度和高度)。
//与minmumWidth和minmumHeight不同的是,widthHint和
//heightHint属性所对应的控件的大小会随着窗口的改变而改变。也是在抢占的方式下,控件才会随着窗口大小的改变而改变。
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class I{public static void main(String[] args){Display display=new Display();Shell shell=new Shell(display);shell.setText("GridLayout网格式布局");GridLayout gridLayout=new GridLayout();gridLayout.numColumns=4;shell.setLayout(gridLayout);//设置控件的大小。widthHint和heightHint属性。//与minmumWidth和minmumHeight不同的是,widthHint和//heightHint属性所对应的控件的大小会随着窗口的改变而改变。GridData gridData=new GridData();//在抢占的方式下,控件才会随着窗口大小的改变而改变。gridData.grabExcessHorizontalSpace=true;gridData.grabExcessVerticalSpace=true;gridData.widthHint=100;//宽度gridData.heightHint=100;//高度new Button(shell,SWT.PUSH).setText("Button1");new Button(shell,SWT.PUSH).setText("按钮2");Button bt3=new Button(shell,SWT.PUSH);bt3.setText("3");bt3.setLayoutData(gridData);new Button(shell,SWT.PUSH).setText("Button4");new Button(shell,SWT.PUSH).setText("按钮5");new Button(shell,SWT.PUSH).setText("66");new Button(shell,SWT.PUSH).setText("Button7");new Button(shell,SWT.PUSH).setText("按钮8");new Button(shell,SWT.PUSH).setText("99");//打开窗口,进行窗口的显示shell.setSize(300,300);//shell.pack();shell.open();while(!shell.isDisposed()){//当窗口没有被释放的时候if(!display.readAndDispatch()){display.sleep();} }display.dispose();}
}
GridLayout网格式布局相关推荐
- java网格式布局登录界面_Java学习笔记------自己书写的登录界面实例
package com.package_view; import com.package_model.*; import javax.swing.*; import java.awt.*; impo ...
- jQuery插件:超酷的多列网格式拖放插件gridster.js
为什么80%的码农都做不了架构师?>>> 日期:2012-8-15 来源:GBin1.com 在线演示 本地下载 以往的文章中,我们分享了很多jQuery相关拖放插件,今天 ...
- html中style布局放哪,CSS样式表与格式布局详解
样式表 CSS(Cascading Style Sheets 层叠样式表),作用是美化HTML网页. 内联样式表: 例: 内联样式表 内嵌样式表:必须写在head标签里 例: p { 样式;} he ...
- 如何将网格式报表打印成其它样式
我们经常要打印报表,也遇到打印上的麻烦,比如有时候我们不想严格按照报表上面的样式,根据实际应用可能有别的样式更适合,这时候怎么办呢,其实报表软件是可以设置,今天我就带大家来了解一下! 1. 问题描述 ...
- latex按照知网格式引用论文
由于知网提供的论文引用格式没有Latex中使用的bib格式的引用格式,因此我们要根据知网中的格式修改为bib格式,以备在latex中引用. 该文提出可以直接使用Endnotes生成知网参考文献的Lat ...
- 揭秘三大运营商在5G专网的布局!
专网通信市场规模逐年增长 专网通信是指通过建设安全可靠的无线服务的专业网络,为特定的部门或群体如政府与公共安全等行业提供应急通信.指挥调度.日常工作通信等服务. 专网通信可以有效弥补了公网通信所无法涉 ...
- 自定义表格式布局FormLayout
自定义表格式布局FormLayout 项目中有这样的表格式布局,如下图 如果用LinearLayout,RelativeLayout也能实现这样的布局,但是比较麻烦,布局的层级也会比较多.所以就自己自 ...
- JavaSwing_1.2: GridLayout(网格布局)
本文链接: http://blog.csdn.net/xietansheng/article/details/72814548 Java Swing 图形界面开发(目录) 1. 概述 官方JavaDo ...
- Java GridLayout(网格布局)布局管理器
GridLayout(网格布局) GridLayout 布局管理器将容器分割成纵横线分隔的网格 , 每个网格所占的区域大小相同.当向使用 GridLayout 布局管理器的容器中添加组件时, 默认 ...
最新文章
- 高精度地图量产难,四维图新利用优势准备实现突破
- (Shadow,Gradient)
- dr.web for android version 9,DrWeb安全防护
- opencv python 图片腐蚀和膨胀
- 平安京服务器维护不能打字,《决战!平安京》:玩的真的累,我真的是服了这破游戏的举报系统...
- 2台电脑间快速复制大文件
- 人间清醒!哈佛女硕士相亲平台找对象,霸气回应:扩大未来伴侣“候选人”样本!...
- MySQL笔记-InnoDB物理及逻辑存储结构
- java抽取注释_JAVA 注解教程(五)注解的提取
- cher怎么翻译中文_中文翻译法语收费标准是怎么定的
- 群晖NAS系统DSM入门
- 计算机显示应用程序错误窗口,电脑开机后弹出netsh.exe应用程序错误提示的解决方法...
- python中easygui()库的使用
- 四通畜牧数据库使用说明
- Vue的模板语法及案例
- 富士通南大实习五月记
- 装在笔记本里的私有云环境:准备篇
- VR沉浸式消防安全演练综合解决方案
- pip install 太慢,迅雷来帮忙
- Insets动画 - 安卓R
热门文章
- 阅读作业之Big Ball of Mud——洪虹
- USB之Cypress的技术支持之资源整合(七)2022-02-23
- python语言头像_python图像处理-个性化头像
- Jin,don't ever do that
- java写的微信红包算法--田小江
- 实用干货!信度分析超全步骤总结!
- 牧师与魔鬼动作分离版
- RocketMQ-Streams架构设计浅析
- [MFC学习笔记]--对话框的设计
- ubuntu18.04安装ISCE2.6.0+CUDA10.2+cuDNN(2022最新安装指南)