Eclipse Form程序设计指南(3)

4、复杂控件

(1)       ExpandableComposite

l         Web页面中一个通用的主题是具有收缩一部分页面内容的能力

l         Eclipse Form也提供了这样一个控件:ExpandableComposite

l         下面的代码片断是使用ExpandableComposite的一个例子:

              ExpandableComposite ec = toolkit.createExpandableComposite(body,

                ExpandableComposite.TREE_NODE

                       | ExpandableComposite.CLIENT_INDENT);

              ec.setText("Expandable Composite title");

              String ctext = "We will now create a somewhat long text so that "

                + "we can use it as content for the expandable composite. "

                + "Expandable composite is used to hide or show the text using the "

                + "toggle control";

              Label client = toolkit.createLabel(ec, ctext, SWT.WRAP);

              ec.setClient(client);

              td = new TableWrapData();

              td.colspan = 2;

              ec.setLayoutData(td);

              ec.addExpansionListener(new ExpansionAdapter() {

                public void expansionStateChanged(ExpansionEvent e) {

                       form.reflow(true);

                }

              });

l         这个控件有很多风格,TREE_NODE使得该控件具有树型节点的展开、收缩功能;而TWISTIE使得控件具有三角箭头风格

l         EXPANDED使得初始展开显示

l         CLIENT_INDENT使得Client内容缩进对齐

l         ExpandableComposite呈现为激活控件和标题,而可以展开、收缩的内容称为Client

l         Client必须是可展开的composite(上例是Label控件)

l         最后需要添加Expansion监听器在状态变化时,reflow Form(即根据控件的新的大小重新定位和更新滚动条)

l         下面是上例的运行结果:

2)Section

l         Eclipse Form中最常用的定制控件就是Section(在PDE中到处可见)

l         Section扩展ExpandableComposite,但具有下面的新特性:

n         在标题下面有一个分隔控件

n         在分隔控件下面可以有一个描述文本

l         下面的代码片断是使用Section的一个例子,代码和ExpandableComposite没有太大差别,这里是用了TWISTIE风格:

              Section section = toolkit.createSection(body, Section.DESCRIPTION

                       | Section.TWISTIE | Section.EXPANDED);

              td = new TableWrapData(TableWrapData.FILL);

              td.colspan = 2;

              section.setLayoutData(td);

              section.addExpansionListener(new ExpansionAdapter() {

                public void expansionStateChanged(ExpansionEvent e) {

                       form.reflow(true);

                }

              });

              section.setText("Section title");

              toolkit.createCompositeSeparator(section);

              section

                       .setDescription("This is the description that goes below the title");

              Composite sectionClient = toolkit.createComposite(section);

              sectionClient.setLayout(new GridLayout());

              button = toolkit.createButton(sectionClient, "Radio 1", SWT.RADIO);

              button = toolkit.createButton(sectionClient, "Radio 2", SWT.RADIO);

              section.setClient(sectionClient);

l         下面是上例的运行结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值