|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
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 下面是上例的运行结果: 返回类别: 教程 上一教程: Java 性能优化技巧集锦 (6) 下一教程: Beginner: Using Servlets to display, insert and update records in database.(3) 您可以阅读与"Eclipse Form程序设计指南(3)"相关的教程: · ECLIPSE FORM程序设计指南之入门 · Eclipse Form程序设计指南(2) · Eclipse Form程序设计指南(1) · ECLIPSE FORM设计指南之定制布局 · 漫谈Java程序设计中的接口应用 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |