中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Java > 综合文章
Eclipse Form程序设计指南(2)
作者:未知 时间:2005-07-27 22:34 出处:CSDN 责编:chinaitpower
              摘要:Eclipse Form程序设计指南(2)

3、定制布局

Eclipse Form提供了2个新的布局

1TableWrapLayout

l         问题:如果将上例中超链接的文本设置的足够长

              link.setText("This is an example of a form that is much longer and will need to wrap.");

即使设置了SWT.WRAP,文本内容不会自动WRAP,这是因为体内容的布局是GridLayout

l         Eclipse Form提供替代的布局TableWrapLayout:类似于GridLayout,但是具有象HTML表格一样自动WRAP功能

l         下面是解决超链接文本自动WRAP的例子:

       public void createPartControl(Composite parent) {

              toolkit = new FormToolkit(parent.getDisplay());

              form = toolkit.createScrolledForm(parent);

              form.setText("Hello, Eclipse Forms");

 

              Composite body = form.getBody();

              TableWrapLayout layout = new TableWrapLayout();

              body.setLayout(layout);

              Hyperlink link = toolkit.createHyperlink(body, "Click here.", SWT.WRAP);

              link.addHyperlinkListener(new HyperlinkAdapter() {

                public void linkActivated(HyperlinkEvent e) {

                       System.out.println("Link activated!");

                }

              });

 

              layout.numColumns = 2;

              link.setText("This is an example of a form that is much longer and will need to wrap.");

              TableWrapData td = new TableWrapData();

              td.colspan = 2;

              link.setLayoutData(td);

              Label label = toolkit.createLabel(body, "Text field label:");

              Text text = toolkit.createText(body, "");

              td = new TableWrapData(TableWrapData.FILL_GRAB);

              text.setLayoutData(td);

              text.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);

              Button button = toolkit.createButton(body,

                       "An example of a checkbox in a form", SWT.CHECK);

              td = new TableWrapData();

              td.colspan = 2;

              button.setLayoutData(td);

              toolkit.paintBordersFor(body);

       }

l         下面是程序变化的地方:

n         TableWrapLayout替代GridLayout

n         使用TableWrapData来提供布局数据信息

n         设置的属性使用colspanrowspan等来源于HTML表格单元的属性

l         要注意的是:需要自动WRAP的控件,需要设置成SWT.WRAP风格

2)ColumnLayout

l         ColumnLayoutEclipse Form提供的另一个定制布局

l         ColumnLayout的布局方式是从上到下,从左到右

l         在变化Form的宽度时,会自动调整控件列数以适应Form的宽度

l         ColumnLayout的设置很简单,通常只要设置列数的范围(缺省是1-3

l         在后面的相关部分会给出使用的例子


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有