﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Leo's Blog-文章分类-Eclipse</title><link>http://www.blogjava.net/leopallas/category/7348.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 11:12:36 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 11:12:36 GMT</pubDate><ttl>60</ttl><item><title>Eclipse Forms: Rich UI for the Rich Client(翻译,第三部分)</title><link>http://www.blogjava.net/leopallas/articles/30165.html</link><dc:creator>Leo</dc:creator><author>Leo</author><pubDate>Fri, 10 Feb 2006 07:42:00 GMT</pubDate><guid>http://www.blogjava.net/leopallas/articles/30165.html</guid><wfw:comment>http://www.blogjava.net/leopallas/comments/30165.html</wfw:comment><comments>http://www.blogjava.net/leopallas/articles/30165.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/leopallas/comments/commentRss/30165.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/leopallas/services/trackbacks/30165.html</trackback:ping><description><![CDATA[<p><strong><font size="4">高级组件(Complex controls)</font></strong><br>Eclipse Forms提供了4个高级组件,这样你能够构建漂亮的UI<wbr>:expandable composite,section,image hyperlink和form text.让我们依次仔细看看它们每一个.</p>

<p>Expandable composite<br>在网页中有个普遍的功能就是让你有能力把一部分网页内容用一个按钮<wbr>来伸缩它.Eclipse Forms提供了这样一个组件:ExpandableCompos<wbr>ite.<br></p>

<pre> ExpandableComposite ec = toolkit.createExpandableComposi<wbr>te(form.getBody<script type="text/javascript"><!--
D(["mb","(), \n     ExpandableComposite.TREE_NODE|\n     ExpandableComposite.CLIENT<WBR>_INDENT);\n ec.setText(&quot;Expandable Composite title&quot;);\n String ctext \u003d &quot;We will now create a somewhat long text so that &quot;+\n &quot;we can use it as content for the expandable composite. &quot;+\n &quot;Expandable composite is used to hide or show the text using the &quot; \n &quot;toggle control&quot;;\n Label client \u003d toolkit.createLabel(ec, ctext, SWT.WRAP);\n ec.setClient(client);\n td \u003d new TableWrapData();\n td.colspan \u003d 2;\n ec.setLayoutData(td);\n ec.addExpansionListener(new ExpansionAdapter() {\n  public void expansionStateChanged(Expansion<WBR>Event e) {\n   form.reflow(true);\n  }\n });</pre>\n<p>这个composite接受一些风格参数来控制它的表现行为<WBR>.TREENODE风格会用树组件中的按钮来伸展或收缩内容,TWISTIE风格则会创建一个方行的按钮.使用EXPANDED,则初始状态是伸展的.如果用COMPACT风格,组件会报告和标题宽度相合适的宽度并且呈现收缩状态.最后,CLIENT_INDENT会使内容与标题对齐(否则<WBR>,内容是按照组件的宽度).</p>\n<p>ExpandableComposite有责任处理按钮组件和标题<WBR>.能扩展和收缩的客户组件必须是expandablecompos<WBR>ite直接的child. 我们需要为组件添加伸展监听器并&quot;通知(reflow)&quot;form在状态改变时.这是因为伸展改变了expandable composite的大小,但是在parent下一次布局前对pa<WBR>rent没有任何影响(因此需要强行告诉它).大体上<WBR>,每次你使form的layout改变时,你需要&quot;reflow<WBR>&quot;这个form.&quot;Reflowing&quot;这个form会让所有组件<WBR>按照新的尺寸布局并更新滚动条.\n</p>\n<div>我们的视图现在看起来象这样：</div>\n<div> </div>\n<div><img height\u003d\"215\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/expandable-closed.gif\" width\u003d\"305\" border\u003d\"0\"><br>图11：一个收缩状态的expandable composite例子</div>\n<div><br>当你点击标题的&quot;+&quot;时,composite伸展出并展示客户:</div>\n<div><img height\u003d\"216\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/expandable-open.gif\" width\u003d\"304\" border\u003d\"0\"></div>\n<div>图12：expandable composite呈伸展状态</div>\n<p>expandable composite用到了一个内部layout,这个layout<WBR>实现了Eclipse Forms ILayoutExtension接口.因此你能够把它加到使用T<WBR>ableWrapLayout布局的parent上,就象我们上面例子中做的一样.</p>\n<p><strong><font size\u003d\"4\">段落(Section)</font></strong><br>Eclipse Forms定制的组件中最versatile之一就是Sectio<WBR>n.它继承了expandable composite并介绍了以下的概念：<br>1.分隔条(Separator)-一个能够在标题下创建的separato<WBR>r组件.<br>2.描述(Description)-在标题下的可选的描述.<br>3.标题栏(Title bar)-能在标题下的一个标题栏(注意separator和标题",1]
);

//--></script>(), <br>     ExpandableComposite.TREE_NODE|<br>     ExpandableComposite.CLIENT<wbr>_INDENT);<br> ec.setText("Expandable Composite title");<br> String ctext = "We will now create a somewhat long text so that "+<br> "we can use it as content for the expandable composite. "+<br> "Expandable composite is used to hide or show the text using the " <br> "toggle control";<br> Label client = toolkit.createLabel(ec, ctext, SWT.WRAP);<br> ec.setClient(client);<br> td = new TableWrapData();<br> td.colspan = 2;<br> ec.setLayoutData(td);<br> ec.addExpansionListener(new ExpansionAdapter() {<br>  public void expansionStateChanged(Expansion<wbr>Event e) {<br>   form.reflow(true);<br>  }<br> });</pre>

<p>这个composite接受一些风格参数来控制它的表现行为<wbr>.TREENODE风格会用树组件中的按钮来伸展或收缩内容,TWISTIE
风格则会创建一个方行的按钮.使用EXPANDED,则初始状态是伸展的.如果用COMPACT风格,组件会报告和标题宽度相合适的宽度并且呈现收缩状
态.最后,CLIENT_INDENT会使内容与标题对齐(否则<wbr>,内容是按照组件的宽度).</p>

<p>ExpandableComposite有责任处理按钮组件和标题<wbr>.能扩展和收缩的客户组件必须是expandablecompos<wbr>ite直接的child. 我们需要为组件添加伸展监听器并"通知(reflow)"form在状态改变时.这是因为伸展改变了expandable composite的大小,但是在parent下一次布局前对pa<wbr>rent没有任何影响(因此需要强行告诉它).大体上<wbr>,每次你使form的layout改变时,你需要"reflow<wbr>"这个form."Reflowing"这个form会让所有组件<wbr>按照新的尺寸布局并更新滚动条. </p>

<div>我们的视图现在看起来象这样：</div>

<div>&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/expandable-closed.gif" alt="" border="0" height="215" width="305"><br>图11：一个收缩状态的expandable composite例子</div>

<div><br>当你点击标题的"+"时,composite伸展出并展示客户:</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/expandable-open.gif" alt="" border="0" height="216" width="304"></div>

<div>图12：expandable composite呈伸展状态</div>

<p>expandable composite用到了一个内部layout,这个layout<wbr>实现了Eclipse Forms ILayoutExtension接口.因此你能够把它加到使用T<wbr>ableWrapLayout布局的parent上,就象我们上面例子中做的一样.</p>

<p><strong><font size="4">段落(Section)</font></strong><br>Eclipse Forms定制的组件中最versatile之一就是Sectio<wbr>n.它继承了expandable composite并介绍了以下的概念：<br>1.分隔条(Separator)-一个能够在标题下创建的separato<wbr>r组件.<br>2.描述(Description)-在标题下的可选的描述.<br>3.标题栏(Title bar)-能在标题下的一个标题栏(注意separator和标题
<script type="text/javascript"><!--
D(["mb","<WBR>栏不能同时使用)\n</p>\n<div>下面的代码和expandable composite代码例子差不多：</div><pre> Section section \u003d toolkit.createSection(form.getBody(), \n  Section.DESCRIPTION|Section<WBR>.TITLE_BAR|\n  Section.TWISTIE|Section<WBR>.EXPANDED);\n td \u003d new TableWrapData(TableWrapData.FILL);\n td.colspan \u003d 2;\n section.setLayoutData(td);\n section.addExpansionListener(new ExpansionAdapter() {\n  public void expansionStateChanged(Expansion<WBR>Event e) {\n   form.reflow(true);\n  }\n });\n section.setText(&quot;Section title&quot;);\n section.setDescription(&quot;This is the description that goes &quot;+\n      below the title&quot;);\n Composite sectionClient \u003d toolkit.createComposite(section);\n sectionClient.setLayout(new GridLayout());\n button \u003d toolkit.createButton(sectionClient, &quot;Radio 1&quot;, SWT.RADIO);\n button \u003d toolkit.createButton(sectionClient, &quot;Radio 2&quot;, SWT.RADIO);\n section.setClient(sectionClient);</pre>\n<div><br>这次我们用了TWISTIE风格,添加了描述并要求有标题栏.这个视图看起来应该象这样：</div>\n<div> </div>\n<div><img height\u003d\"255\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/section.gif\" width\u003d\"305\" border\u003d\"0\"><br>图13：一个有标题栏和描述的可伸展的section</div>\n<p><strong><font size\u003d\"4\">图片超链接(Image hyperlink)</font></strong><br>图片超链接是超链接的子类,它在链接文字上面添加了一个图片.这个平常的结合非常有意义<WBR>.这个组件可以只是一个图片(当没有设置任何文字时),或是图片加链接.图片在正常,hover,激活时的状态都能设置.</p>\n<p>下面是一个用图片超链接的例子：</p>\n<div><img height\u003d\"430\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/intro.gif\" width\u003d\"616\" border\u003d\"0\"></div>\n<div>图片14：Eclipse欢迎页面中的form</div>\n<div><strong><font size\u003d\"4\">Form text组件</font></strong><br>使标签(labels),超链接,图片和TableWrapLay<WBR>out相结合,能够创建出复杂和强大的forms.但是仍然有一些事是很难做的<WBR>.考虑PDE manifest编辑器的例子：<br> </div>\n<div><img height\u003d\"466\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/plugin-overview.gif\" width\u003d\"532\" border\u003d\"0\"></div>\n<div>图片15：一个混合了文本,图片和超链接的复杂Eclipse form例子</div>\n<p>注意图片,超链接和文本是如何混合的.这里使用单独的标签和超链接组件是很困<WBR>难的.为了解决这个问题,Eclipse Forms插件提供了一个强大的文本组件,它有以下功能：<br>识别普通包裹的文本<br>识别普通文本,但是如果以http://开头的文本以超链接显示<br>识别象HTML语言一样的文本</p>\n<p>在所有模式下,form text组件能识别一个字符串或输入流(input stream).</p>\n<p>",1]
);

//--></script>
<wbr>栏不能同时使用) </p>

<div>下面的代码和expandable composite代码例子差不多：</div>

<pre> Section section = toolkit.createSection(form.getBody(), <br>  Section.DESCRIPTION|Section<wbr>.TITLE_BAR|<br>  Section.TWISTIE|Section<wbr>.EXPANDED);<br> td = new TableWrapData(TableWrapData.FILL);<br> td.colspan = 2;<br> section.setLayoutData(td);<br> section.addExpansionListener(new ExpansionAdapter() {<br>  public void expansionStateChanged(Expansion<wbr>Event e) {<br>   form.reflow(true);<br>  }<br> });<br> section.setText("Section title");<br> section.setDescription("This is the description that goes "+<br>      below the title");<br> Composite sectionClient = toolkit.createComposite(section);<br> sectionClient.setLayout(new GridLayout());<br> button = toolkit.createButton(sectionClient, "Radio 1", SWT.RADIO);<br> button = toolkit.createButton(sectionClient, "Radio 2", SWT.RADIO);<br> section.setClient(sectionClient);</pre>

<div><br>这次我们用了TWISTIE风格,添加了描述并要求有标题栏.这个视图看起来应该象这样：</div>

<div>&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/section.gif" alt="" border="0" height="255" width="305"><br>图13：一个有标题栏和描述的可伸展的section</div>

<p><strong><font size="4">图片超链接(Image hyperlink)</font></strong><br>图片超链接是超链接的子类,它在链接文字上面添加了一个图片.这个平常的结合非常有意义<wbr>.这个组件可以只是一个图片(当没有设置任何文字时),或是图片加链接.图片在正常,hover,激活时的状态都能设置.</p>

<p>下面是一个用图片超链接的例子：</p>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/intro.gif" alt="" border="0" height="430" width="616"></div>

<div>图片14：Eclipse欢迎页面中的form</div>

<div><strong><font size="4">Form text组件</font></strong><br>使标签(labels),超链接,图片和TableWrapLay<wbr>out相结合,能够创建出复杂和强大的forms.但是仍然有一些事是很难做的<wbr>.考虑PDE manifest编辑器的例子：<br>&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/plugin-overview.gif" alt="" border="0" height="466" width="532"></div>

<div>图片15：一个混合了文本,图片和超链接的复杂Eclipse form例子</div>

<p>注意图片,超链接和文本是如何混合的.这里使用单独的标签和超链接组件是很困<wbr>难的.为了解决这个问题,Eclipse Forms插件提供了一个强大的文本组件,它有以下功能：<br>识别普通包裹的文本<br>识别普通文本,但是如果以http://开头的文本以超链接显示<br>识别象HTML语言一样的文本</p>

<p>在所有模式下,form text组件能识别一个字符串或输入流(input stream).</p>

<p>
<script type="text/javascript"><!--
D(["mb","<strong>识别普通文本(标签模式)</strong><br>FormText formText \u003d toolkit.createFormText(form.getBody(), true);<br> td \u003d new TableWrapData(TableWrapData.FILL);<br> td.colspan \u003d 2;<br> formText.setLayoutData(td);<br> String text \u003d &quot;Here is some plain text for the text to render.&quot;;\n<br> formText.setText(text, false, false);<br>第二个参数设为false,意思是我们不需要解析html标记<WBR>,第三个参数设为false,意思是我们不需扩展URLs.</p>\n<div><strong>自动将URLs转化为超链接<br></strong>现在我们会在文本中添加一个超链接,并把第3个参数设为true:<br>FormText formText \u003d toolkit.createFormText(form.getBody(), true);<br> td \u003d new TableWrapData(TableWrapData.FILL);<br> td.colspan \u003d 2;<br> formText .setLayoutData(td);\n<br> String text \u003d &quot;Here is some plain text for the text to render; &quot;+<br>   this text is at <a href\u003d\"http://www.eclipse.org/\" target\u003d\"_blank\" onclick\u003d\"return top.js.OpenExtLink(window,event,this)\">http://www.eclipse.org</a> web site.&quot;;<br> formText .setText(text, false, true);\n<br>如果看我们的视图,会是这样：</div>\n<div> </div>\n<div><img height\u003d\"287\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/form-text1.gif\" width\u003d\"305\" border\u003d\"0\"><br>图16：Form text组件将URL自动转化为超链接</div>\n<p>URL被转化为了链接.这个链接是包裹的文本中的一部分<WBR>-我们不需要创建单独的超链接组件然后试着把它夹在两个标签中间.<br>因为form text组件能够识别超链接,因此它接收我们前面用过的监听器.当由toolkit创建时,form text会将toolkit的超链接组设置作为新超链接的设置.<br></p>\n",0]
);
D(["ce"]);
D(["ms","220a"]
);

//--></script>
<strong>识别普通文本(标签模式)</strong><br>FormText formText = toolkit.createFormText(form.getBody(), true);<br>&nbsp;td = new TableWrapData(TableWrapData.FILL);<br>&nbsp;td.colspan = 2;<br>&nbsp;formText.setLayoutData(td);<br>&nbsp;String text = "Here is some plain text for the text to render."; <br>&nbsp;formText.setText(text, false, false);<br>第二个参数设为false,意思是我们不需要解析html标记<wbr>,第三个参数设为false,意思是我们不需扩展URLs.</p>

<div><strong>自动将URLs转化为超链接<br></strong>现在我们会在文本中添加一个超链接,并把第3个参数设为true:<br>FormText formText = toolkit.createFormText(form.getBody(), true);<br>&nbsp;td = new TableWrapData(TableWrapData.FILL);<br>&nbsp;td.colspan = 2;<br>&nbsp;formText .setLayoutData(td); <br>&nbsp;String text = "Here is some plain text for the text to render; "+<br>&nbsp;&nbsp; this text is at <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.eclipse.org/" target="_blank">http://www.eclipse.org</a> web site.";<br>&nbsp;formText .setText(text, false, true); <br>如果看我们的视图,会是这样：</div>

<div>&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/form-text1.gif" alt="" border="0" height="287" width="305"><br>图16：Form text组件将URL自动转化为超链接</div>

<p>URL被转化为了链接.这个链接是包裹的文本中的一部分<wbr>-我们不需要创建单独的超链接组件然后试着把它夹在两个标签中间.<br>因为form text组件能够识别超链接,因此它接收我们前面用过的监听器.当由toolkit创建时,form text会将toolkit的超链接组设置作为新超链接的设置.<br>
</p>

转自：http://blog.csdn.net/starshus/archive/2006/02/07/593808.aspx<img src ="http://www.blogjava.net/leopallas/aggbug/30165.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/leopallas/" target="_blank">Leo</a> 2006-02-10 15:42 <a href="http://www.blogjava.net/leopallas/articles/30165.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse Forms: Rich UI for the Rich Client(翻译,第二部分)</title><link>http://www.blogjava.net/leopallas/articles/30162.html</link><dc:creator>Leo</dc:creator><author>Leo</author><pubDate>Fri, 10 Feb 2006 07:39:00 GMT</pubDate><guid>http://www.blogjava.net/leopallas/articles/30162.html</guid><wfw:comment>http://www.blogjava.net/leopallas/comments/30162.html</wfw:comment><comments>http://www.blogjava.net/leopallas/articles/30162.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/leopallas/comments/commentRss/30162.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/leopallas/services/trackbacks/30162.html</trackback:ping><description><![CDATA[<p><strong><font size="4">增加一些内容</font></strong><br>现在我们已经有一个view能够成功运行了.我们可以往里面增加一<wbr>些内容.Eclipse forms有一个body,我们可以这样创建内容.<br></p>

<pre>public void createPartControl(Composite parent) {<br>  toolkit = new FormToolkit(parent.getDisplay());<br>  form = toolkit.createForm(parent);<br>  form.setText("Hello, Eclipse Forms");<br>  GridLayout layout = new GridLayout();<br> <img src="http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif" alt="" align="bottom" height="13" width="24"> form.getBody().setLayout(layout);<br> <img src="http://www.eclipse.org/articles/Article-Forms/images/tag_2.gif" alt="" align="bottom" height="13" width="24"> Hyperlink link = toolkit.createHyperlink(form.getBody(), <br>    "Click here.", SWT.WRAP);<br> <img src="http://www.eclipse.org/articles/Article-Forms/images/tag_3.gif" alt="" align="bottom" height="13" width="24"> link.addHyperlinkListener(new HyperlinkAdapter() {<br>   public void linkActivated(HyperlinkEvent e) {<br>    System.out.println("Link activated!");<br>   }<br>  });<br> }</pre>

<p>form的body是标题下面的可用空间.因为这个空间是一个SW<wbr>T Composite,它能做为其它组件的parent.在上面的代码里,<img src="http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif" alt="" align="bottom" height="13" width="24">我们为body设置了layout,<img src="http://www.eclipse.org/articles/Article-Forms/images/tag_2.gif" alt="" align="bottom" height="13" width="24"> 然后创建了一个超链接.超链接是由Eclipse Forms提供的为数不多的组件之一.我们可以为超链接<img src="http://www.eclipse.org/articles/Article-Forms/images/tag_3.gif" alt="" align="bottom" height="13" width="24">增加监听器,这样能够在用户点击它时做出反应.</p>

<div>升级后的视图应该看起来象这样：</div>

<div>&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/click-here.gif" alt="" border="0" height="222" width="198"></div>

<div>图3：一个有超链接的简单form.</div>

<p><strong><font size="4">超链接组(Hyperlink Groups)<br></font></strong>Form tookit有一个"超链接组"对象.每个创建出的超链接都加入这个组对象中.超链接为多个角色服<wbr>务.它们定义了这个组中所有超链接在正常、hover、激活不同状态下的颜色.它们根据小组中链接不同的状态来改变颜色<wbr>.它们根据小组中链接不同的状态来改变下划线风格.</p>

<p>当你要改变超链接组对象的默认设置时,可以通过toolkit的g<wbr>etHyperlinkGroup()方法来获得超链接组对象.</p>

<p><strong><font size="4">
<script type="text/javascript"><!--
D(["mb","创建普通组件</font></strong></p>\n<div>Eclipse Forms的一个设计目标就是让能够在编辑器/视图中创建普通SW<WBR>T组件.因为form的body是一个普通composite,你能够在它里面使用任何layout和组件.但是,记住&quot;原生的&quot;SWT组件有一个组件背景.我们现在通过它们的构造方法创建一些组<WBR>件.<br><pre>  layout.numColumns \u003d 2;\n  GridData gd \u003d new GridData();\n  gd.horizontalSpan \u003d 2;\n  link.setLayoutData(gd);\n  Label label \u003d new Label(form.getBody(), SWT.NULL);\n  label.setText(&quot;Text field label:&quot;);\n  Text text \u003d new Text(form.getBody(), SWT.BORDER);\n  text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));\n  Button button \u003d new Button(form.getBody(), SWT.CHECK);\n  button.setText(&quot;An example of a checkbox in a form&quot;);\n  gd \u003d new GridData();\n  gd.horizontalSpan \u003d 2;\n  button.setLayoutData(gd);</pre><br>现在我们使用了两列,并且创建了一个标签(label)<WBR>,一个文本框(text field)和一个复选框(checkbox).结果如下：</div>\n<div> </div>\n<div><img height\u003d\"183\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/no-toolkit.gif\" width\u003d\"240\" border\u003d\"0\"><br>图4：一个拥有直接用它们的构造器创建出的SWT组件的form</div>\n<div> </div>\n<div>这张图片怎么回事？我们创建的组件的背景直接和系统窗口背景相匹配<WBR>,而不是和form的背景匹配.另外,文本框看起来还好是因为这张截图是在Windows XP下截的.在其它操作系统上,它会看起来是有一个3D边框的空白条.为了解决这个问题,我们会用toolkit的工厂方法来创建这些组件：<br><pre>  Label label \u003d toolkit.createLabel(form.getBody(), &quot;Text field label:&quot;);\n  Text text \u003d toolkit.createText(form.getBody(), &quot;&quot;);\n  text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));\n  Button button \u003d toolkit.createButton(form.getBody(), &quot;A checkbox in a form&quot;, SWT.CHECK);\n  gd \u003d new GridData();\n  gd.horizontalSpan \u003d 2;\n  button.setLayoutData(gd);</pre></div>\n<div>这个视图现在会看来更好些了：</div>\n<div> </div>\n<div><img height\u003d\"177\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/with-toolkit.gif\" width\u003d\"233\" border\u003d\"0\"><br>图5：一个拥有用form toolkit的工厂方法创建出的SWT组件的form</div>\n<div><br>由form toolkit提供的工厂方法是为了方便.Toolkit没有函盖<WBR>所有情况,甚至是SWT组件集合,而且明显没有为你可能有的自己定制的组件提供这一便利<WBR>.当你需要使一个SWT组件与form统一时,你应该使用一个方法:FormToolkit.adapt(Control control, boolean trackFocus, boolean trackKeyboard).所有的工厂方法各自分别调用了这个<WBR>适配方法.</div>\n\n<p><strong><font size\u003d\"4\">达到&quot;平滑&quot;的视觉效果</font>",1]
);

//--></script>
创建普通组件</font></strong></p>

<div>Eclipse Forms的一个设计目标就是让能够在编辑器/视图中创建普通SW<wbr>T组件.因为form的body是一个普通composite,你能够在它里面使用任何layout和组件.但是,记住"原生的"SWT组件有一个组件背景.我们现在通过它们的构造方法创建一些组<wbr>件.<br>
<pre>  layout.numColumns = 2;<br>  GridData gd = new GridData();<br>  gd.horizontalSpan = 2;<br>  link.setLayoutData(gd);<br>  Label label = new Label(form.getBody(), SWT.NULL);<br>  label.setText("Text field label:");<br>  Text text = new Text(form.getBody(), SWT.BORDER);<br>  text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));<br>  Button button = new Button(form.getBody(), SWT.CHECK);<br>  button.setText("An example of a checkbox in a form");<br>  gd = new GridData();<br>  gd.horizontalSpan = 2;<br>  button.setLayoutData(gd);</pre>
<br>现在我们使用了两列,并且创建了一个标签(label)<wbr>,一个文本框(text field)和一个复选框(checkbox).结果如下：</div>

<div>&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/no-toolkit.gif" alt="" border="0" height="183" width="240"><br>图4：一个拥有直接用它们的构造器创建出的SWT组件的form</div>

<div>&nbsp;</div>

<div>这张图片怎么回事？我们创建的组件的背景直接和系统窗口背景相匹配<wbr>,而不是和form的背景匹配.另外,文本框看起来还好是因为这张截图是在Windows XP下截的.在其它操作系统上,它会看起来是有一个3D边框的空白条.为了解决这个问题,我们会用toolkit的工厂方法来创建这些组件：<br>
<pre>  Label label = toolkit.createLabel(form.getBody(), "Text field label:");<br>  Text text = toolkit.createText(form.getBody(), "");<br>  text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));<br>  Button button = toolkit.createButton(form.getBody(), "A checkbox in a form", SWT.CHECK);<br>  gd = new GridData();<br>  gd.horizontalSpan = 2;<br>  button.setLayoutData(gd);</pre>
</div>

<div>这个视图现在会看来更好些了：</div>

<div>&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/with-toolkit.gif" alt="" border="0" height="177" width="233"><br>图5：一个拥有用form toolkit的工厂方法创建出的SWT组件的form</div>

<div><br>由form toolkit提供的工厂方法是为了方便.Toolkit没有函盖<wbr>所有情况,甚至是SWT组件集合,而且明显没有为你可能有的自己定制的组件提供这一便利<wbr>.当你需要使一个SWT组件与form统一时,你应该使用一个方法:FormToolkit.adapt(Control control, boolean trackFocus, boolean trackKeyboard).所有的工厂方法各自分别调用了这个<wbr>适配方法.</div>

<p><strong><font size="4">达到"平滑"的视觉效果</font>
<script type="text/javascript"><!--
D(["mb","</strong></p>\n<p>一个在PDE编辑器中Eclipse Forms的可看出的属性是组件的&quot;平滑&quot;视觉效果.以前所有没有3D边框的组件在窗口中看起来不错,但是在编辑器或视图中就不行.这个支持写在FormToolkit<WBR>类中.但是,在一些系统上它是通过一些定制达到的.举个例子,看一下这张从PDE编辑器(2.1版本)中的截图：</p>\n<div><img height\u003d\"507\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/plugin-dependencies.gif\" width\u003d\"545\" border\u003d\"0\"></div>\n<div>图片6：Eclipse 2.1中Eclipse Forms的平滑视觉效果.</div>\n<div><br>象表格,文本类,复选框等,是加上一个平滑的1个象素宽的边框.这些边框不是来自组件自己(SWT.BORDER风格没有用到).另外,如果设置一下,tookit会为每个组件的parent<WBR>增加一个paint监听器,在paint事件发生时为组件加上边框.要想这样的话,你需要为你创建的象文本,表格,树等组件的每个composit<WBR>e调用paintBordersFor(parent)<WBR>.每个parent只需要调用一次方法就足够了：不需要为每个组件<WBR>这样调用.\n</div>\n<p>Form toolkit知道哪个组件需要一个定制的边框.但是,你可能新创建了一个不在原来名单中的组件,它也需要一个边框.你可以通过象下面这样的代码给toolkit一<WBR>个提示：</p><pre>Control myControl \u003d new MyControl(parent);\nmyControl.setData(FormToolkit.KEY_DRAW_BORDER, <strong>FormToolkit.TEXT_BORDER</strong>);\n// or myControl.setData(FormToolkit.KEY_DRAW_BORDER, <strong>FormToolkit.TREE_BORDER</strong>);\ntoolkit.paintBordersFor(parent);</pre>\n<p>你可以在上面这张图中看出,象树和表格这样的&quot;结构化<WBR>(structural)&quot;的组件有和文本区域不同的边框风格并且你可以选择和你的组件相符合<WBR>的那个.注意用toolkit的工厂方法创建出的组件不需要这样做.</p>\n<p><img height\u003d\"13\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/win_only.gif\" width\u003d\"49\"> 因为Eclipse 3.0和在Windows XP上,当javaw.exe.manifest文件在Java虚拟机bi<WBR>n文件夹中时,没有边框产生出来.(这篇文章里我所有截图都是在Windows XP下截的).这个文件--你可以在<a href\u003d\"http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-swt-home/faq.html#xpthemes\" target\u003d\"_blank\" onclick\u003d\"return top.js.OpenExtLink(window,event,this)\">\nSWT home page</a>上下载--告诉toolkit为本地组件使用XP皮肤.用XP皮肤,象文本,表格和树是已经平滑的并且不需要再去调整.为了让你的代码拥有可移<WBR>植性,你可以总是调用paintBordersFor<WBR>(Composite)方法,让toolkit去根据不同操作系统<WBR>来决定该怎么做.</p>\n<p><strong><font size\u003d\"4\">定制布局(Custom layouts)</font></strong><br>Eclipse Forms在SWT layout的基础上增加了两个新的layout<WBR>.这些layout继承了SWT Layout基类并能够在任何SWT composite上使用,但是一般都是和Eclipse Forms联合使用的.</p>\n<div><strong><font size\u003d\"4\">TableWrapLayout</font></strong><br>现在我们知道如何来组合一个form,让我们先给一个悬念.我们会改变那个超链接文本使它加长一些：<br>link.setText(&quot;This is an example of a form that is much longer &quot;+",1]
);

//--></script>
</strong></p>

<p>一个在PDE编辑器中Eclipse Forms的可看出的属性是组件的"平滑"视觉效果.以前所有没有3D边框的组件在窗口中看起来不错,但是在编辑器或视图中就不行.这个支持写在FormToolkit<wbr>类中.但是,在一些系统上它是通过一些定制达到的.举个例子,看一下这张从PDE编辑器(2.1版本)中的截图：</p>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/plugin-dependencies.gif" alt="" border="0" height="507" width="545"></div>

<div>图片6：Eclipse 2.1中Eclipse Forms的平滑视觉效果.</div>

<div><br>象表格,文本类,复选框等,是加上一个平滑的1个象素宽的边框.这些边框不是来自组件自己(SWT.BORDER风格没有用到).另外,如果设置一下,tookit会为每个组件的parent<wbr>增加一个paint监听器,在paint事件发生时为组件加上边框.要想这样的话,你需要为你创建的象文本,表格,树等组件的每个composit<wbr>e调用paintBordersFor(parent)<wbr>.每个parent只需要调用一次方法就足够了：不需要为每个组件<wbr>这样调用. </div>

<p>Form toolkit知道哪个组件需要一个定制的边框.但是,你可能新创建了一个不在原来名单中的组件,它也需要一个边框.你可以通过象下面这样的代码给toolkit一<wbr>个提示：</p>

<pre>Control myControl = new MyControl(parent);<br>myControl.setData(FormToolkit.KEY_DRAW_BORDER, <strong>FormToolkit.TEXT_BORDER</strong>);<br>// or myControl.setData(FormToolkit.KEY_DRAW_BORDER, <strong>FormToolkit.TREE_BORDER</strong>);<br>toolkit.paintBordersFor(parent);</pre>

<p>你可以在上面这张图中看出,象树和表格这样的"结构化<wbr>(structural)"的组件有和文本区域不同的边框风格并且你可以选择和你的组件相符合<wbr>的那个.注意用toolkit的工厂方法创建出的组件不需要这样做.</p>

<p><img src="http://www.eclipse.org/articles/Article-Forms/images/win_only.gif" alt="" height="13" width="49">&nbsp;因为Eclipse 3.0和在Windows XP上,当javaw.exe.manifest文件在Java虚拟机bi<wbr>n文件夹中时,没有边框产生出来.(这篇文章里我所有截图都是在Windows XP下截的).这个文件--你可以在<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/faq.html#xpthemes" target="_blank"> SWT home page</a>上下载--告诉toolkit为本地组件使用XP皮肤.用XP皮肤,象文本,表格和树是已经平滑的并且不需要再去调整.为了让你的代码拥有可移<wbr>植性,你可以总是调用paintBordersFor<wbr>(Composite)方法,让toolkit去根据不同操作系统<wbr>来决定该怎么做.</p>

<p><strong><font size="4">定制布局(Custom layouts)</font></strong><br>Eclipse Forms在SWT layout的基础上增加了两个新的layout<wbr>.这些layout继承了SWT Layout基类并能够在任何SWT composite上使用,但是一般都是和Eclipse Forms联合使用的.</p>

<div><strong><font size="4">TableWrapLayout</font></strong><br>现在我们知道如何来组合一个form,让我们先给一个悬念.我们会改变那个超链接文本使它加长一些：<br>link.setText("This is an example of a form that is much longer "+
<script type="text/javascript"><!--
D(["mb","<br>                     &quot;and will need to wrap.&quot;);\n<br>让我们看看结果：</div>\n<div> </div>\n<div><img height\u003d\"177\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/long-link.gif\" width\u003d\"233\" border\u003d\"0\"><br>图片7：一个使用GridLayout的form</div>\n<p>发生什么事了？记住我们使用的是GridLayout<WBR>.当它问这个超链接组件来计算它大小时,超链接告诉它文字在单独行里需要的长度.虽然我们告诉组件去包裹(wrap),它并没有这样做因为GridLayout需要组件返回它的长度<WBR>.超连接组件--和其它象Label一样的SWT组件,可以通过你传递它数值来决定<WBR>长和宽,但是GridLayout不会向组件传递数值参数.</p>\n<p>我们需要的是一个象HTML表格一样的layout<WBR>.我们希望内容去试图配合提供的客户空间,并且一行行地叠加.Eclipse Forms提供了一个这样的layout叫TableWrapLa<WBR>yout.GridLayout和TableWrapLayout<WBR>之间有许多共同点.都是用表格来组织parent的childre<WBR>n.都有layout data来告诉layout如何对待每个组件.都能够在需要占据所<WBR>有空间时等接受组件的提示.</p>\n<p>但是,它们在布局时完全不同.TableWrapLayout从列开始<WBR>.它计算每列的最小的,合适的,最大的宽度并用这个信息来占据空间.它也试图尽可能地公平地在各列<WBR>间分隔,这样有些组件就没有多余的空间.</p>\n<div>让我们使用TableWrapLayout来重新更改例子<WBR>(更改处高亮显示)：</div>\n<div> </div>\n<div><pre> public void createPartControl(Composite parent) {\n  toolkit \u003d new FormToolkit(parent.getDisplay());\n  form \u003d toolkit.createForm(parent);\n  form.setText(&quot;Hello, Eclipse Forms&quot;);\n  <b><font color\u003d\"#ff0000\">TableWrapLayout layout \u003d new TableWrapLayout();</font></b>\n  form.getBody().setLayout(layout);\n  Hyperlink link \u003d toolkit.createHyperlink(form.getBody(),&quot;Click here.&quot;, SWT.WRAP);\n  link.addHyperlinkListener(new HyperlinkAdapter() {\n   public void linkActivated(HyperlinkEvent e) {\n    System.out.println(&quot;Link activated!&quot;);\n   }\n  });\n  link.setText(&quot;This is an example of a form that is much longer and will need to wrap.&quot;);\n  layout.numColumns \u003d 2;\n  <b><font color\u003d\"#ff0000\">TableWrapData td \u003d new TableWrapData();\n  td.colspan \u003d 2;\n  link.setLayoutData(td);</font></b>\n  Label label \u003d toolkit.createLabel(form.getBody(), &quot;Text field label:&quot;);\n  Text text \u003d toolkit.createText(form.getBody(), &quot;&quot;);\n  <b><font color\u003d\"#ff0000\">td \u003d new TableWrapData(TableWrapData.FILL_GRAB);\n  text.setLayoutData(td);</font></b>\n  Button button \u003d toolkit.createButton(form.getBody(), &quot;A checkbox in a form&quot;, ",1]
);

//--></script>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"and will need to wrap."); <br>让我们看看结果：</div>

<div>&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/long-link.gif" alt="" border="0" height="177" width="233"><br>图片7：一个使用GridLayout的form</div>

<p>发生什么事了？记住我们使用的是GridLayout<wbr>.当它问这个超链接组件来计算它大小时,超链接告诉它文字在单独行里需要的长度.虽然我们告诉组件去包裹(wrap),它并没有这样做因为GridLayout需要组件返回它的长度<wbr>.超连接组件--和其它象Label一样的SWT组件,可以通过你传递它数值来决定<wbr>长和宽,但是GridLayout不会向组件传递数值参数.</p>

<p>我们需要的是一个象HTML表格一样的layout<wbr>.我们希望内容去试图配合提供的客户空间,并且一行行地叠加.Eclipse Forms提供了一个这样的layout叫TableWrapLa<wbr>yout.GridLayout和TableWrapLayout<wbr>之间有许多共同点.都是用表格来组织parent的childre<wbr>n.都有layout data来告诉layout如何对待每个组件.都能够在需要占据所<wbr>有空间时等接受组件的提示.</p>

<p>但是,它们在布局时完全不同.TableWrapLayout从列开始<wbr>.它计算每列的最小的,合适的,最大的宽度并用这个信息来占据空间.它也试图尽可能地公平地在各列<wbr>间分隔,这样有些组件就没有多余的空间.</p>

<div>让我们使用TableWrapLayout来重新更改例子<wbr>(更改处高亮显示)：</div>

<div>&nbsp;</div>

<div>
<pre> public void createPartControl(Composite parent) {<br>  toolkit = new FormToolkit(parent.getDisplay());<br>  form = toolkit.createForm(parent);<br>  form.setText("Hello, Eclipse Forms");<br>  <strong><font color="#ff0000">TableWrapLayout layout = new TableWrapLayout();</font></strong><br>  form.getBody().setLayout(layout);<br>  Hyperlink link = toolkit.createHyperlink(form.getBody(),"Click here.", SWT.WRAP);<br>  link.addHyperlinkListener(new HyperlinkAdapter() {<br>   public void linkActivated(HyperlinkEvent e) {<br>    System.out.println("Link activated!");<br>   }<br>  });<br>  link.setText("This is an example of a form that is much longer and will need to wrap.");<br>  layout.numColumns = 2;<br>  <strong><font color="#ff0000">TableWrapData td = new TableWrapData();<br>  td.colspan = 2;<br>  link.setLayoutData(td);</font></strong><br>  Label label = toolkit.createLabel(form.getBody(), "Text field label:");<br>  Text text = toolkit.createText(form.getBody(), "");<br>  <strong><font color="#ff0000">td = new TableWrapData(TableWrapData.FILL_GRAB);<br>  text.setLayoutData(td);</font></strong><br>  Button button = toolkit.createButton(form.getBody(), "A checkbox in a form", <script type="text/javascript"><!--
D(["mb","SWT.CHECK);\n  <b><font color\u003d\"#ff0000\">td \u003d new TableWrapData();\n  td.colspan \u003d 2;\n  button.setLayoutData(td);</font></b>\n }</pre><pre><br><br>我们用了GridData相同的概念.一些变量拥有不同的名字(举个例子,colspan和rowspan,align和val<WBR>ign取自HTML TABLE的属性),但是你可以做相同的事--创建一个超链接和按钮占据两列的格子<WBR\>.因为空白(margins)和GridLayout是相同的<WBR>,结果会看起来一样,除了超链接现在会包裹起来：</pre><pre><img height\u003d\"177\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/wrapped-link.gif\" width\u003d\"233\" border\u003d\"0\">\n<br>图片8：一个使用TableWrapLayout的form</pre></div>\n<p>TableWrapLayout和GridLayout的一个主要<WBR>的不同点是你应该停止去计算垂直的空间.在GridLayout里,你一般会让&quot;不易变形的(rigid)&quot;组件用自然的位置和大小<WBR>并让&quot;可伸缩的(flexible)&quot;组件去占据水平或垂直的空间.相反,TableWrapLayout是从上往下工作的<WBR>,并且它容下所有的组件,它的工作是完全的.占据水平空间的概念还存在(象上面展示一样).但是,垂直方向上,你只能在单元(cell<WBR>)比组件高时选择FILL单元,或选择TOP,MIDDLE或BO<WBR>TTOM垂直对齐.\n<br>你也许会注意到一个地方和刚刚说的不符：TableWrapLay<WBR>out仍然有一个grabVertical变量.但是<WBR>,这里这个变量在这里有明确的目的：当一个设置了高度的组件占多行<WBR>时,它的高度会给出一个条件就是垂直dimension已经知道了<WBR>,组件需要去除它所在的多个单元之间的多余空间.</p>\n<p>为了用TableWrapLayout有好的结果<WBR>,确定组件可以接近风格(SWT.WRAP).Eclipse Froms提供的组合定制组件能够在box外面包裹<WBR>.这是通过实现ILayoutExtension接口实现的：<br>public interface ILayoutExtension {<br>   /**<br>    * Computes the minimum width of the parent. All widgets capable of word\n<br>    * wrapping should return the width of the longest word that cannot be<br>    * broken any further.<br>    * <br>    * @param parent the parent composite<br>    * @param changed &lt;code&gt;true&lt;/code&gt; if the cached information should be\n<br>    * flushed, &lt;code&gt;false&lt;/code&gt; otherwise.<br>    * @return the minimum width of the parent composite<br>    */<br>   public int computeMinimumWidth(Composite parent, boolean changed);</p>\n<p>   /**<br>    * Computes the maximum width of the parent. All widgets capable of word<br>    * wrapping should return the length of the entire text with wrapping<br>    * turned off.<br>    * <br>    * @param parent the parent composite\n<br>    * @param changed &lt;code&gt;true&lt;/code&gt; if the cached information<br>    * should be flushed, &lt;code&gt;false&lt;/code&gt; otherwise.",1]
);

//--></script>SWT.CHECK);<br>  <strong><font color="#ff0000">td = new TableWrapData();<br>  td.colspan = 2;<br>  button.setLayoutData(td);</font></strong><br> }</pre>
<pre><br><br>我们用了GridData相同的概念.一些变量拥有不同的名字(举个例子,colspan和rowspan,align和val<wbr>ign取自HTML TABLE的属性),但是你可以做相同的事--创建一个超链接和按钮占据两列的格子<wbr>.因为空白(margins)和GridLayout是相同的<wbr>,结果会看起来一样,除了超链接现在会包裹起来：</pre>
<pre><img src="http://www.eclipse.org/articles/Article-Forms/images/wrapped-link.gif" alt="" border="0" height="177" width="233"><br><br>图片8：一个使用TableWrapLayout的form</pre>
</div>

<p>TableWrapLayout和GridLayout的一个主要<wbr>的不同点是你应该停止去计算垂直的空间.在GridLayout里,你一般会让"不易变形的(rigid)"组件用自然的位置和大小<wbr>并让"可伸缩的(flexible)"组件去占据水平或垂直的空间.相反,TableWrapLayout是从上往下工作的<wbr>,并且它容下所有的组件,它的工作是完全的.占据水平空间的概念还存在(象上面展示一样).但是,垂直方向上,你只能在单元(cell<wbr>)比组件高时选择FILL单元,或选择TOP,MIDDLE或BO<wbr>TTOM垂直对齐. <br>你也许会注意到一个地方和刚刚说的不符：TableWrapLay<wbr>out仍然有一个grabVertical变量.但是<wbr>,这里这个变量在这里有明确的目的：当一个设置了高度的组件占多行<wbr>时,它的高度会给出一个条件就是垂直dimension已经知道了<wbr>,组件需要去除它所在的多个单元之间的多余空间.</p>

<p>为了用TableWrapLayout有好的结果<wbr>,确定组件可以接近风格(SWT.WRAP).Eclipse Froms提供的组合定制组件能够在box外面包裹<wbr>.这是通过实现ILayoutExtension接口实现的：<br>public interface ILayoutExtension {<br>&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Computes the minimum width of the parent. All widgets capable of word <br>&nbsp;&nbsp;&nbsp; * wrapping should return the width of the longest word that cannot be<br>&nbsp;&nbsp;&nbsp; * broken any further.<br>&nbsp;&nbsp;&nbsp; * <br>&nbsp;&nbsp;&nbsp; * @param parent the parent composite<br>&nbsp;&nbsp;&nbsp; * @param changed &lt;code&gt;true&lt;/code&gt; if the cached information should be <br>&nbsp;&nbsp;&nbsp; * flushed, &lt;code&gt;false&lt;/code&gt; otherwise.<br>&nbsp;&nbsp;&nbsp; * @return the minimum width of the parent composite<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp;&nbsp; public int computeMinimumWidth(Composite parent, boolean changed);</p>

<p>&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Computes the maximum width of the parent. All widgets capable of word<br>&nbsp;&nbsp;&nbsp; * wrapping should return the length of the entire text with wrapping<br>&nbsp;&nbsp;&nbsp; * turned off.<br>&nbsp;&nbsp;&nbsp; * <br>&nbsp;&nbsp;&nbsp; * @param parent the parent composite <br>&nbsp;&nbsp;&nbsp; * @param changed &lt;code&gt;true&lt;/code&gt; if the cached information<br>&nbsp;&nbsp;&nbsp; * should be flushed, &lt;code&gt;false&lt;/code&gt; otherwise.
<script type="text/javascript"><!--
D(["mb","<br>    * @return the maximum width of the parent composite<br>    */<br>\n   public int computeMaximumWidth(Composite parent, boolean changed);<br>}<br>TableWrapLayout本身实现了这个接口,这样让它处理当composites的layout是这个comp<WBR>osite的parent的children的情况<WBR>.另外的两个方法能够计算两种极端情况--当所有组件尽可能宽地布满时的显然的最小宽度和最大宽度<WBR>.两者的不同是使列之间的多余空间尽可能小时贡献出公平的空间.\n</p>\n<div>让我们看清楚贡献空间是怎样的.我们会推荐我们到现在为止写的代码<WBR>并象下面这样做出修改：</div>\n<div> </div>\n<div><pre> layout.numColumns \u003d 3;\n Label label;\n TableWrapData td;\n \n label \u003d toolkit.createLabel(form.getBody(), \n  &quot;Some text to put in the first column&quot;, SWT.WRAP);\n label \u003d toolkit.createLabel(form.getBody(),\n  &quot;Some text to put in the second column and make it a bit &quot;+\n  &quot;longer so that we can see what happens with column &quot;+\n  distribution. This text must be the longest so that it can &quot;+\n  &quot;get more space allocated to the columns it belongs to.&quot;, \n  SWT.WRAP);\n td \u003d new TableWrapData();\n td.colspan \u003d 2;\n label.setLayoutData(td);\n label \u003d toolkit.createLabel(form.getBody(), \n  &quot;This text will span two rows and should not grow the column.&quot;, \n  SWT.WRAP);\n td \u003d new TableWrapData();\n td.rowspan \u003d 2;\n label.setLayoutData(td);\n label \u003d toolkit.createLabel(form.getBody(), \n  &quot;This text goes into column 2 and consumes only one cell&quot;, \n  SWT.WRAP);\n label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));\n label \u003d toolkit.createLabel(form.getBody(), \n  &quot;This text goes into column 3 and consumes only one cell too&quot;, \n  SWT.WRAP);\n label.setLayoutData(new TableWrapData(TableWrapData.FILL));\n label \u003d toolkit.createLabel(form.getBody(), \n  &quot;This text goes into column 2 and consumes only one cell&quot;, \n  SWT.WRAP);\n label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));\n label \u003d toolkit.createLabel(form.getBody(), \n  &quot;This text goes into column 3 and consumes only one cell too&quot;, \n  SWT.WRAP);\n label.setLayoutData(new TableWrapData(TableWrapData.FILL));\n<img height\u003d\"13\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif\" width\u003d\"24\" align\u003d\"baseline\">",1]
);

//--></script>
<br>&nbsp;&nbsp;&nbsp; * @return the maximum width of the parent composite<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp;&nbsp; public int computeMaximumWidth(Composite parent, boolean changed);<br>}<br>TableWrapLayout本身实现了这个接口,这样让它处理当composites的layout是这个comp<wbr>osite的parent的children的情况<wbr>.另外的两个方法能够计算两种极端情况--当所有组件尽可能宽地布满时的显然的最小宽度和最大宽度<wbr>.两者的不同是使列之间的多余空间尽可能小时贡献出公平的空间. </p>

<div>让我们看清楚贡献空间是怎样的.我们会推荐我们到现在为止写的代码<wbr>并象下面这样做出修改：</div>

<div>&nbsp;</div>

<div>
<pre> layout.numColumns = 3;<br> Label label;<br> TableWrapData td;<br> <br> label = toolkit.createLabel(form.getBody(), <br>  "Some text to put in the first column", SWT.WRAP);<br> label = toolkit.createLabel(form.getBody(),<br>  "Some text to put in the second column and make it a bit "+<br>  "longer so that we can see what happens with column "+<br>  distribution. This text must be the longest so that it can "+<br>  "get more space allocated to the columns it belongs to.", <br>  SWT.WRAP);<br> td = new TableWrapData();<br> td.colspan = 2;<br> label.setLayoutData(td);<br> label = toolkit.createLabel(form.getBody(), <br>  "This text will span two rows and should not grow the column.", <br>  SWT.WRAP);<br> td = new TableWrapData();<br> td.rowspan = 2;<br> label.setLayoutData(td);<br> label = toolkit.createLabel(form.getBody(), <br>  "This text goes into column 2 and consumes only one cell", <br>  SWT.WRAP);<br> label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));<br> label = toolkit.createLabel(form.getBody(), <br>  "This text goes into column 3 and consumes only one cell too", <br>  SWT.WRAP);<br> label.setLayoutData(new TableWrapData(TableWrapData.FILL));<br> label = toolkit.createLabel(form.getBody(), <br>  "This text goes into column 2 and consumes only one cell", <br>  SWT.WRAP);<br> label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));<br> label = toolkit.createLabel(form.getBody(), <br>  "This text goes into column 3 and consumes only one cell too", <br>  SWT.WRAP);<br> label.setLayoutData(new TableWrapData(TableWrapData.FILL));<br><img src="http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif" alt="" align="bottom" height="13" width="24"><script type="text/javascript"><!--
D(["mb"," form.getBody().setBackground(form.getBody().getDisplay().\n    getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));</pre><pre><br>这个创建了一些有不同长度文本的label.有些labels占据<WBR>多列,有些占据多行.为了让测试更加简单,<img height\u003d\"13\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif\" width\u003d\"24\" align\u003d\"baseline\">\n我们把form的背景设置为组件背景,这样单元能够更简单看出来.当我们运行例子,我们会得到下面的样子：</pre><pre><img height\u003d\"275\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/wrapped-layout.gif\" width\u003d\"266\" border\u003d\"0\"><br>图片9：TableWrapLayout留下的多余空间</pre></div>\n\n<p>关键之处在于组件最小宽度和最大宽度相比较时.相差越多,结果越明显,会看到列中有很大的缝隙.占据的宽度是组件所需要的最小的宽度<WBR>.注意第3列比第2列稍微宽一点点,这是因为第3列中的文字长度比第2列中文字要长点<WBR>.如果需要阅读布局的相关理论,可以去这里W3C recommendations for HTML table auto-layout.</p>\n<p><strong><font size\u003d\"4\">ColumnLayout</font></strong><br>Eclipse Forms另外一个定制的layout是SWT RowLayout的变种.如果我们把RowLayout上的ch<WBR>ildren垂直放置时--按列-并且使同列中的所有组件拥有相同的宽度,我们会由组件的宽度得到多个列.但是,最后一列显然不是被填满的--这由组件的个数决定<WBR\>.如果在form中,我们会仍然看到所有组件在一列中,因为RowLayout不能够<WBR>&quot;垂直&quot;\n包裹.如果我们用GridLayout相替代的话,列的数量由我们自己决定.</p>\n<p>在更加复杂的forms中我们需要列的数量按情况变化.换句话来说,我们希望数字按照form的宽度来改变--有可能需要更多的列,当宽度减小时则把数字减小.而且我们希望所有列的长度象报纸布局一<WBR>样相同.这些要求都能够通过ColumnLayout来达到.</p>\n<p>与TableWrapLayout相比,ColumnLayout更加简单.不需要复杂的设置<WBR>.唯一需要你设置的就是列数的范围,默认是1到3.下面的例子演示了一个使用ColumnLayout<WBR>的有许多段落(sections)的form.初始时,只需要两列就可以放置所有段落了.如果我们把编辑器变窄一点,layout会使它们在同一列中.</p>\n<div><img height\u003d\"481\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/two-columns.gif\" width\u003d\"583\" border\u003d\"0\"> </div>\n<div><img height\u003d\"480\" src\u003d\"http://www.eclipse.org/articles/Article-Forms/images/one-column.gif\" width\u003d\"413\" border\u003d\"0\"></div>\n<div>图片10：使用ColumnLayout的所有按列排列的段落<WBR>.layout开始是两列,但是按照空间的改变变成了一列.</div>\n<p><strong><font size\u003d\"4\">高级组件(Complex controls)</font></strong><br>Eclipse Forms提供了4个高级组件,这样你能够构建漂亮的UI<WBR>:expandable composite,section,image hyperlink和form text.让我们依次仔细看看它们每一个.</p>\n<p>Expandable composite<br>在网页中有个普遍的功能就是让你有能力把一部分网页内容用一个按钮<WBR>来伸缩它.Eclipse Forms提供了这样一个组件:ExpandableCompos<WBR>ite.<br></p><pre> ExpandableComposite ec \u003d toolkit.createExpandableComposi<WBR>te(form.getBody",1]
);

//--></script> form.getBody().setBackground(form.getBody().getDisplay().<br>    getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));</pre>
<pre><br>这个创建了一些有不同长度文本的label.有些labels占据<wbr>多列,有些占据多行.为了让测试更加简单,<img src="http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif" alt="" align="bottom" height="13" width="24"><br>我们把form的背景设置为组件背景,这样单元能够更简单看出来.当我们运行例子,我们会得到下面的样子：</pre>
<pre><img src="http://www.eclipse.org/articles/Article-Forms/images/wrapped-layout.gif" alt="" border="0" height="275" width="266"><br>图片9：TableWrapLayout留下的多余空间</pre>
</div>

<p>关键之处在于组件最小宽度和最大宽度相比较时.相差越多,结果越明显,会看到列中有很大的缝隙.占据的宽度是组件所需要的最小的宽度<wbr>.注意第3列比第2列稍微宽一点点,这是因为第3列中的文字长度比第2列中文字要长点<wbr>.如果需要阅读布局的相关理论,可以去这里W3C recommendations for HTML table auto-layout.</p>

<p><strong><font size="4">ColumnLayout</font></strong><br>Eclipse Forms另外一个定制的layout是SWT RowLayout的变种.如果我们把RowLayout上的ch<wbr>ildren垂直放置时--按列-并且使同列中的所有组件拥有相同的宽度,我们会由组件的宽度得到多个列.但是,最后一列显然不是被填满的--这由组件的个数决定<wbr>.如果在form中,我们会仍然看到所有组件在一列中,因为RowLayout不能够<wbr>"垂直" 包裹.如果我们用GridLayout相替代的话,列的数量由我们自己决定.</p>

<p>在更加复杂的forms中我们需要列的数量按情况变化.换句话来说,我们希望数字按照form的宽度来改变--有可能需要更多的列,当宽度减小时则把数字减小.而且我们希望所有列的长度象报纸布局一<wbr>样相同.这些要求都能够通过ColumnLayout来达到.</p>

<p>与TableWrapLayout相比,ColumnLayout更加简单.不需要复杂的设置<wbr>.唯一需要你设置的就是列数的范围,默认是1到3.下面的例子演示了一个使用ColumnLayout<wbr>的有许多段落(sections)的form.初始时,只需要两列就可以放置所有段落了.如果我们把编辑器变窄一点,layout会使它们在同一列中.</p>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/two-columns.gif" alt="" border="0" height="481" width="583">&nbsp;</div>

<div><img src="http://www.eclipse.org/articles/Article-Forms/images/one-column.gif" alt="" border="0" height="480" width="413"></div>

图片10：使用ColumnLayout的所有按列排列的段落
<div><wbr>.layout开始是两列,但是按照空间的改变变成了一列.<br>
<br>
转自：http://blog.csdn.net/starshus/archive/2006/02/07/593785.aspx</div>
<img src ="http://www.blogjava.net/leopallas/aggbug/30162.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/leopallas/" target="_blank">Leo</a> 2006-02-10 15:39 <a href="http://www.blogjava.net/leopallas/articles/30162.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse Forms: Rich UI for the Rich Client(翻译,第一部分)</title><link>http://www.blogjava.net/leopallas/articles/30161.html</link><dc:creator>Leo</dc:creator><author>Leo</author><pubDate>Fri, 10 Feb 2006 07:36:00 GMT</pubDate><guid>http://www.blogjava.net/leopallas/articles/30161.html</guid><wfw:comment>http://www.blogjava.net/leopallas/comments/30161.html</wfw:comment><comments>http://www.blogjava.net/leopallas/articles/30161.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/leopallas/comments/commentRss/30161.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/leopallas/services/trackbacks/30161.html</trackback:ping><description><![CDATA[<div class="postTitle">
		<a href="http://blog.csdn.net/starshus/archive/2006/01/23/586576.aspx">Eclipse Forms: 为胖客户端做的漂亮UI(翻译,第一部分)</a>
<script language="javascript">document.title="Eclipse Forms: 为胖客户端做的漂亮UI(翻译,第一部分) - "+document.title</script>
	</div>

	
	
	
	
		
<p>这篇文章是我为eclipse中国社区翻译的,今天才翻译了前面一点点.版权归原作者,原文作者应该不会生气吧:P<br>原文见:http://www.eclipse.org/articles/Article-Forms/article.html</p>


<p><strong>Summary</strong><br>这篇文章将告诉你如何在你的胖客户端程序中加入Eclipse
Forms.Eclipse
Forms可以在你的程序里不通过嵌入浏览器而达到Web效果.这样可以不仅对组件保持完全控制而且不失eclipse所有的可移植性.这篇文章将从
Eclipse Forms的基本特性到高级特性一步一步指导你.</p>


<p><strong>By Dejan Glozic, IBM Canada Ltd.</strong></p>


<p>January 16, 2005</p>


<p><strong>历史</strong><br>一个Eclipse平台的基本特性是:所有基于Eclipse平台开发的程序界面能够象本地程序一
样.因为SWT,菜单,窗口,树,表格,按钮和其它组件在任何操作系统上都和系统风格保持一致.作为Eclipse小组最早的一个成员,我记得开发
eclipse原型代码快乐的日子.菜单是真的,工具栏是真的,复选菜单,文本框,按钮,复选框,单选按钮都是真的.它们不是画出来的,都是调用的操作系
统的本地组件.</p>


<p>很长一段时间里,如果你写过Eclipse插件,它们基本上是属于下面的范围:<br>1.Editors (编辑器)<br>2.Views (视图)<br>3.Wizards (向导)<br>4.Dialog (窗口)<br>这个范围都有明确的规则规定了如何编写插件.我们已经看过了views里的树,表格,editors里的文档,还有简单的象在向导和窗口里的按钮和文本框.</p>


<p>Eclipse 3.x里的RCP在系统上扩展了一系列新的特性.它带来了许多问题有效的解决方案.你现在可以在eclipse上构建和IDE完全不同的RCP程序</p>


<p>.虽然一般的工作台部分比如视图和编辑器工作的很好,但是构成这些部分的组件(树,表格,文本编辑器等)在RCP里有时候可能不是最好的解决办法.从Eclipse 3.0起,Eclipse Forms被设计为来提供替代的解决方案.</p>


<p>具有讽刺意味的是,我们开发出的Eclipse Forms解决了一个比RCP早很长时间就存在于Eclipse
SDK中的一个问题.使用专门编辑plugin.xml的带语法分析,颜色显示的文本编辑器的PDE开发者并不高兴.Eclipse的Java编辑器并没
有什么问题,它非常强大,对于这个任务也很理想.但是,它是用来编辑Java代码的.在插件manifests里,xml是用来在更高层次上抽象描述数据
结构的.手工编辑xml,即使是使用带语法分析,颜色显示的编辑器,
大部分用户也觉得不太合适.在插件manifests里,语法不是重点.具体的数据和它的意思才是重点.</p>


<p>一个很好的不同例子是用HTML识别工具来查看标记.在代码的角度,我们可以清楚地看见含有相关属性的元素.虽然我们看到语法,但是很难看清楚它到
底要表现什么.一个WYSIWYG视图可以显示表格,颜色,还有一些含有表格,图片等的文本内容.在这个角度使用html文件更加具有生产效率,</p>


<p>因为语法和标记被隐藏在后台了.</p>


<p>弄明白对于html文档的WYSIWYG概念很简单.因为HTML标签是用来展示为浏览器写一个来表现属性,超链接和图片的文本文档结构的,
WYSIWYG在这方面意味着在它最终的形式上编辑文档--近可能和它在浏览器上的形式相同.指出用不同的方法的一个编辑插件manifest编辑器的外
观很难.最终工作小组做出了以下决定:<br>1.用最合适它的方法来展示manifest的每个部分.举个例子,象插件名称,提供者等重要信息可以简单的通过一个文本框来编辑.象扩展点定义这样带有阶层的数据结构则通过树来展现 .<br>2.通过各个单独的编辑页面来展示manifest的各个部分,顺序则按照它本来在代码中的顺序.<br>3.编辑器的每个页面应该保持文档的风格,并能够容纳不同的组件,超级链接,图片,文本,并在对于页面尺寸内容太多时提供一个滚动条.</p>


<p><img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/plugin-overview.jpg" border="0" height="488" width="546"></p>


<p><strong>图片1</strong>：Eclipse SDK1.0中的插件manifest编辑器.它容纳了SWT组件,超链接和图片,并且当尺寸不够时能够滚动(就象web浏览器一样).注意为了看起来和文本内容更加融合,所有组件都是平滑的(flat).</p>


<p>第三点有效地促使了它作为现在以Eclipse Forms为名称的插件产生.在1.0发布后,其它的开发者希望能够复制PDE多页面编辑器的胖客户端接口.</p>


<p>它最终作为Eclipse3.0中带有公共API的插件发布了.</p>


<p>在下面的文章里,我们将告诉你什么是Eclipse Forms(和什么不是Eclipse Forms),并如何用简单的使用它们来创造漂亮的界面.</p>


<p><strong>Eclipse Forms Mission</strong></p>


<p>Eclipse Forms是一个<img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif" align="bottom" height="13" width="24">贯穿所有Eclipse UI的<img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_2.gif" align="bottom" height="13" width="24">基于SWT和JFace的来<img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_3.gif" align="bottom" height="13" width="24">提供可移植Web风格用户界面的<img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_4.gif" align="bottom" height="13" width="24">可选胖客户端插件.<br><img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif" align="bottom" height="13" width="24">Eclipse Forms打破了只能用于特定Eclipse UI(编辑器,视图,向导,窗口)的模式.为了满足开发者的需要,一个Eclipse form能够以任何UI的形式出现.UI开发者能够使用为他们的任务选择最合适的概念.<br><img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_2.gif" align="bottom" height="13" width="24">Eclipse不是用来设计完全替代SWT或JFace的.这个插件只有一些精心挑选的专有定制组件 ,布局和支持类,以便使用SWT和JFace时达到预期效果.<br><img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_3.gif" align="bottom" height="13" width="24">很
明显的,一个Eclipse
Form通常看起来象网页一样.事实是form的纲领可行性的各方面都是使forms强大的和具有吸引力.要同过浏览器达到这样的弹性需要DOM支持,并
且经常几乎是聚耦的.Eclipse Forms是可移植的,并且是在SWT和JFace之上写的.<br><img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_4.gif" align="bottom" height="13" width="24">Eclipse Forms已经在3.0 release中重写来只依赖于平台UI插件,而不再依赖于PDE UI插件.虽然它们还不是RCP的最小化部分,但是你能够在任何RCP程序中添加Eclipse Forms.</p>


<p>要点<img alt="2" src="http://www.eclipse.org/articles/Article-Forms/images/tag_2.gif" align="bottom" height="13" width="24"> 不能被低估.当构建Eclipse Forms时,你是在使用SWT.没有Eclipse Forms按钮,也没有Eclipse Forms tree组件等等.你只是使用Eclipse Forms来让现有的组件达到客户体验.</p>


<p>Eclipse Forms是通过下列元素来达到目的的:<br>"form"概念和视图,编辑器等是一个层次的概念.<br>一个工具包(toolkit)来管理颜色,超链接组还有其它方面.并且充当许多SWT组件的工厂类.<br>一个新的layout manager来管理布局,和HTML表格相似.<br>一组定制的组件用来配合form.(超链接,图片超链接,滚动组合&lt;scrollable composite&gt;,段&lt;section&gt;)<br>一个各个页面都是forms的多页面编辑器(e.g. PDE manifest编辑器)</p>


<p><img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tip.gif" border="0" height="13" width="62">&nbsp;
虽然Eclipse
Forms的设计中没有任何阻止您在一个窗口中建立form.但是大部分时候都是在视图和编辑器中使用forms,而不是窗口或向导.的确,在一个普通的
窗口或向导中加入form看上去有点怪,毕竟其他部分都是普通的SWT组件.无论如何,在未来,这是一个探索的方向.</p>


<p><strong>Baby steps</strong><br>在您的用户接口中使用Eclipse Forms非常简单.在开始前你在插件依赖部分加入org.eclipse.ui.forms插件.我们会创建一个拥有form的</p>


<p>Eclipse view,然后往里面填充内容.注意这篇文章插件的所有代码都以zip文件格式提供下载.</p>


<p>Hello, Eclipse Forms<br>我们从往view里添加一个空白form来开始游戏:</p>


<p><font face="Courier New">public class FormView extends ViewPart {<br>&nbsp;private FormToolkit toolkit;<br>&nbsp;private ScrolledForm form;</font></p>


<p><font face="Courier New">&nbsp;/**<br>&nbsp; * The constructor.<br>&nbsp; */<br>&nbsp;public FormView() {<br>&nbsp;}</font></p>


<p><font face="Courier New">&nbsp;/**<br>&nbsp; * This is a callback that will allow us to create the viewer and<br>&nbsp; * initialize it.<br>&nbsp; */<br>&nbsp;public void createPartControl(Composite parent) {<br>&nbsp; <img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif" align="bottom" height="13" width="24">toolkit = new FormToolkit(parent.getDisplay());<br>&nbsp; <img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_2.gif" align="bottom" height="13" width="24">form = toolkit.createScrolledForm(parent);<br>&nbsp; <img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_3.gif" align="bottom" height="13" width="24">form.setText("Hello, Eclipse Forms");<br>&nbsp;}</font></p>


<p><font face="Courier New">&nbsp;/**<br>&nbsp; * Passing the focus request to the form.<br>&nbsp; */<br>&nbsp;public void setFocus() {<br>&nbsp; form.setFocus();<br>&nbsp;}</font></p>


<p><font face="Courier New">&nbsp;/**<br>&nbsp; * Disposes the toolkit<br>&nbsp; */<br>&nbsp;public void dispose() {<br>&nbsp; toolkit.dispose();<br>&nbsp; super.dispose();<br>&nbsp;}<br>}</font><br>就象你在这段代码中看到一样,不需要太多就可以创建一个form.我们开始是创建一个toolkit实例(<img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_1.gif" align="bottom" height="13" width="24">).我们通过toolkit以提供的composite为parent来<img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_2.gif" align="bottom" height="13" width="24">创建一个可以滚动的form.我们设置了<img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/tag_3.gif" align="bottom" height="13" width="24">form的标题.而且我们确定在需要的时候把focus传给form,当view dispose时把toolkit也dispose掉.</p>


<p>这个视图应该看起来象这样:</p>


<p class="center"><img alt="" src="http://www.eclipse.org/articles/Article-Forms/images/hello1.gif" border="0" height="221" width="217"></p>


<strong>图片2:</strong><br>

在view里的一个空的form,使view变窄一点会让form标题包裹起来,一旦没有空间来容纳整个form,滚动条就会显示.<br>

注
意我们用到了可滚动的form,因为我们把它放到了一个可以改变大小的视图中.在更复杂的环境里,比如一个form需要作为一个布局的一部分,没有滚动能
力的form也可以用.在这种情况下,我们会调用FormToolkit.createForm(),让外层的parent来解决需要滚动条的问题.<br>

<br>

转自：http://blog.csdn.net/starshus/archive/2006/01/23/586576.aspx<img src ="http://www.blogjava.net/leopallas/aggbug/30161.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/leopallas/" target="_blank">Leo</a> 2006-02-10 15:36 <a href="http://www.blogjava.net/leopallas/articles/30161.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>