• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Eclipse Form程序设计指南(3)

servlet/jsp 搞代码 7年前 (2018-06-18) 127次浏览 已收录 0个评论

4、复杂控件

(1)       ExpandableComposite

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

http://www.gaodaima.com/40524.htmlEclipse Form程序设计指南(3)

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         下面是上例的运行结果:

欢迎大家阅读《Eclipse Form程序设计指南(3)》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Eclipse Form程序设计指南(3)

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址