java swt gridlayout_SWT界面布局介绍之GridLayout
GridLayout網格布局時最常用的布局之一,類似于Html中使用table布局。通過使用GridData來設置布局參數。
做個例子看看。
代碼:
import?org.eclipse.swt.SWT;
import?org.eclipse.swt.layout.FillLayout;
import?org.eclipse.swt.layout.GridData;
import?org.eclipse.swt.layout.GridLayout;
import?org.eclipse.swt.widgets.Button;
import?org.eclipse.swt.widgets.Composite;
import?org.eclipse.swt.widgets.Display;
import?org.eclipse.swt.widgets.Group;
import?org.eclipse.swt.widgets.Label;
import?org.eclipse.swt.widgets.List;
import?org.eclipse.swt.widgets.Shell;
import?org.eclipse.swt.widgets.Text;
/**
*?SWT?FillLayout布局使用demo?發(fā)郵件
*?@author?xwalker
*
*/
public?class?GridLayoutDemo{
private?Shell?shell;
private?Text?toAddrText;
private?Text?topicText;
private?Text?ccText;
private?Text?labelText;
private?Button?sendBtn;
private?Button?timSendBtn;
private?Button?saveBtn;
private?Composite?composite;
private?Group?group;
public?void?open()?{
Display?display?=?Display.getDefault();
createContents();
while?(!shell.isDisposed())?{
if?(!display.readAndDispatch())?{
display.sleep();
}
}
}
/**
*?創(chuàng)建窗口組件
*/
protected?void?createContents(){
shell=new?Shell();
shell.setText("發(fā)郵件");
shell.setSize(800,?450);
shell.setLayout(new?GridLayout(5,?false));
Label?toLabel?=?new?Label(shell,?SWT.NONE);
toLabel.setLayoutData(new?GridData(SWT.RIGHT,?SWT.CENTER,?false,?false,?1,?1));
toLabel.setText("收件人");
toAddrText?=?new?Text(shell,?SWT.BORDER);
toAddrText.setLayoutData(new?GridData(SWT.FILL,?SWT.CENTER,?true,?false,?3,?1));
composite?=?new?Composite(shell,?SWT.NONE);
composite.setLayout(new?FillLayout(SWT.HORIZONTAL));
GridData?gd_composite?=?new?GridData(SWT.FILL,?SWT.FILL,?false,?false,?1,?4);
gd_composite.widthHint?=?171;
composite.setLayoutData(gd_composite);
group?=?new?Group(composite,?SWT.NONE);
group.setText("聯系人");
group.setLayout(new?FillLayout(SWT.HORIZONTAL));
List?list?=?new?List(group,?SWT.BORDER);
insertData(list);
Label?topiclabel?=?new?Label(shell,?SWT.NONE);
topiclabel.setLayoutData(new?GridData(SWT.RIGHT,?SWT.CENTER,?false,?false,?1,?1));
topiclabel.setText("主題");
topicText?=?new?Text(shell,?SWT.BORDER);
topicText.setLayoutData(new?GridData(SWT.FILL,?SWT.CENTER,?true,?false,?3,?1));
Label?ccLabel?=?new?Label(shell,?SWT.NONE);
ccLabel.setLayoutData(new?GridData(SWT.RIGHT,?SWT.CENTER,?false,?false,?1,?1));
ccLabel.setText("抄送");
ccText?=?new?Text(shell,?SWT.BORDER);
ccText.setLayoutData(new?GridData(SWT.FILL,?SWT.CENTER,?true,?false,?3,?1));
Label?contentLabel?=?new?Label(shell,?SWT.NONE);
contentLabel.setLayoutData(new?GridData(SWT.RIGHT,?SWT.CENTER,?false,?false,?1,?1));
contentLabel.setText("內容");
labelText?=?new?Text(shell,?SWT.BORDER);
GridData?gd_labelText?=?new?GridData(SWT.FILL,?SWT.FILL,?true,?false,?3,?1);
gd_labelText.heightHint?=?232;
labelText.setLayoutData(gd_labelText);
new?Label(shell,?SWT.NONE);
sendBtn?=?new?Button(shell,?SWT.NONE);
sendBtn.setText("發(fā)送");
timSendBtn?=?new?Button(shell,?SWT.NONE);
timSendBtn.setText("定時發(fā)送");
saveBtn?=?new?Button(shell,?SWT.NONE);
saveBtn.setText("存草稿");
new?Label(shell,?SWT.NONE);
shell.open();
}
private?void?insertData(List?list)?{
for(int?i=1;i<=20;i++){
list.add("聯系人"+i);
}
}
public?static?void?main(String[]?args)?{
GridLayoutDemo?demo=new?GridLayoutDemo();
demo.open();
}
}
總結
以上是生活随笔為你收集整理的java swt gridlayout_SWT界面布局介绍之GridLayout的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: access ribbon 编程_Acc
- 下一篇: 编译原理实验二:Bison