Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14417767
  • 博文数量: 5645
  • 博客积分: 9880
  • 博客等级: 中将
  • 技术积分: 68081
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-28 13:35
文章分类

全部博文(5645)

文章存档

2008年(5645)

我的朋友

分类:

2008-04-28 21:44:49

下载本文示例代码
  3、定制布局   Eclipse Form提供了2个新的布局  (1)TableWrapLayout  ·问题:如果将上例中超链接的文本设置的足够长 link.setText("This is an example of a form that is much longer and will need to wrap.");  即使设置了SWT.WRAP,文本内容不会自动WRAP,这是因为体内容的布局是GridLayout  ·Eclipse Form提供替代的布局TableWrapLayout:类似于GridLayout,但是具有象HTML表格一样自动WRAP功能  ·下面是解决超链接文本自动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);}  ·下面是程序变化的地方:  1) TableWrapLayout替代GridLayout  2) 使用TableWrapData来提供布局数据信息  3) 设置的属性使用colspan、rowspan等来源于HTML表格单元的属性  ·要注意的是:需要自动WRAP的控件,需要设置成SWT.WRAP风格  (2)ColumnLayout  ·ColumnLayout是Eclipse Form提供的另一个定制布局  ·ColumnLayout的布局方式是从上到下,从左到右  ·在变化Form的宽度时,会自动调整控件列数以适应Form的宽度  ·ColumnLayout的设置很简单,通常只要设置列数的范围(缺省是1-3)  ·在后面的相关部分会给出使用的例子 阅读关于 Eclipse 的全部文章   3、定制布局   Eclipse Form提供了2个新的布局  (1)TableWrapLayout  ·问题:如果将上例中超链接的文本设置的足够长 link.setText("This is an example of a form that is much longer and will need to wrap.");  即使设置了SWT.WRAP,文本内容不会自动WRAP,这是因为体内容的布局是GridLayout  ·Eclipse Form提供替代的布局TableWrapLayout:类似于GridLayout,但是具有象HTML表格一样自动WRAP功能  ·下面是解决超链接文本自动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);}  ·下面是程序变化的地方:  1) TableWrapLayout替代GridLayout  2) 使用TableWrapData来提供布局数据信息  3) 设置的属性使用colspan、rowspan等来源于HTML表格单元的属性  ·要注意的是:需要自动WRAP的控件,需要设置成SWT.WRAP风格  (2)ColumnLayout  ·ColumnLayout是Eclipse Form提供的另一个定制布局  ·ColumnLayout的布局方式是从上到下,从左到右  ·在变化Form的宽度时,会自动调整控件列数以适应Form的宽度  ·ColumnLayout的设置很简单,通常只要设置列数的范围(缺省是1-3)  ·在后面的相关部分会给出使用的例子 阅读关于 Eclipse 的全部文章 下载本文示例代码


Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局Eclipse Form设计指南之定制布局
阅读(214) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~