专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Java教程 » ui组件:Eclipse Forms设计漂亮UI的高级组件 »正文

ui组件:Eclipse Forms设计漂亮UI的高级组件

来源: 发布时间:星期四, 2009年1月8日 浏览:11次 评论:0
  Eclipse Forms提供了4个高级组件这样你能够构建漂亮UI:expandable composite,section,image hyperlink和form text.让我们依次仔细看看它们每

  Expandable composite

  在网页中有个普遍功能就是让你有能力把部分网页内容用个按钮来伸缩它Eclipse Forms提供了这样个组件:ExpandableComposite

ExpandableComposite ec = toolkit.createExpandableComposite(form.getBody,
ExpandableComposite.TREE_NODE|
ExpandableComposite.CLIENT_INDENT);
ec.Text("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.Client(client);
td = TableWrapData;
td.colspan = 2;
ec.LayoutData(td);
ec.addExpansionListener( ExpansionAdapter {
public void expansionStateChanged(ExpansionEvent e) {
form.reflow(true);
}
});
这个composite接受些风格参数来控制它表现行为.TREENODE风格会用树组件中按钮来伸展或收缩内容,TWISTIE风格则会创建个方行按钮.使用EXPANDED,则状态是伸展.如果用COMPACT风格,组件会报告和标题宽度相合适宽度并且呈现收缩状态.最后,CLIENT_INDENT会使内容和标题对齐(否则,内容是按照组件宽度).

  ExpandableComposite有责任处理按钮组件和标题.能扩展和收缩客户组件必须是expandablecomposite直接child. 我们需要为组件添加伸展监听器并"通知(reflow)"form在状态改变时.这是伸展改变了expandable composite大小,但是在parent下次布局前对parent没有任何影响(因此需要强行告诉它).大体上,每次你使formlayout改变时,你需要"reflow"这个form."Reflowing"这个form会让所有组件按照新尺寸布局并更新滚动条.

  我们视图现在看起来象这样:



  图16:Form text组件将URL自动转化为超链接

  URL被转化为了链接.这个链接是包裹文本中部分-我们不需要创建单独超链接组件然后试着把它夹在两个标签中间.

  form text组件能够识别超链接,因此它接收我们前面用过监听器.当由toolkit创建时,form text会将toolkit超链接组设置作为新超链接设置.



相关文章

读者评论

发表评论

  • 昵称:
  • 内容: