服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

eclipse form设计指南之定制布局


  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)

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

扫描关注微信公众号