expandablecomposite ec = toolkit.createexpandablecomposi這個composite接受一些風格參數(shù)來控制它的表現(xiàn)行為te(form.getbody(), 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(expansion event e) { form.reflow(true); } }); 


section section = toolkit.createsection(form.getbody(), section.description|section.title_bar| section.twistie|section .expanded); td = new tablewrapdata(tablewrapdata.fill); td.colspan = 2; section.setlayoutdata(td); section.addexpansionlistener(new expansionadapter() { public void expansionstatechanged(expansion event e) { form.reflow(true); } }); section.settext("section title"); 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); 
  這次我們用了twistie風格,添加了描述并要求有標題欄.這個視圖看起來應該象這樣:
 
圖13:一個有標題欄和描述的可伸展的section
  圖片超鏈接(image hyperlink)
  圖片超鏈接是超鏈接的子類,它在鏈接文字上面添加了一個圖片.這個平常的結合非常有意義
  下面是一個用圖片超鏈接的例子:
圖片14:eclipse歡迎頁面中的form
  form text組件
  使標簽(labels),超鏈接,圖片和tablewraplay
 
圖片15:一個混合了文本,圖片和超鏈接的復雜eclipse form例子
  注意圖片,超鏈接和文本是如何混合的.這里使用單獨的標簽和超鏈接組件是很困
  識別普通包裹的文本
  識別普通文本,但是如果以http://開頭的文本以超鏈接顯示
  識別象html語言一樣的文本
  在所有模式下,form text組件能識別一個字符串或輸入流(input stream).
  識別普通文本(標簽模式)
formtext formtext = toolkit.createformtext(form.getbody(), true);
 td = new tablewrapdata(tablewrapdata.fill);
 td.colspan = 2;
 formtext.setlayoutdata(td);
 string text = "here is some plain text for the text to render."; 
 formtext.settext(text, false, false);
  第二個參數(shù)設為false,意思是我們不需要解析html標記
  自動將urls轉化為超鏈接
  現(xiàn)在我們會在文本中添加一個超鏈接,并把第3個參數(shù)設為true:
formtext formtext = toolkit.createformtext(form.getbody(), true);
 td = new tablewrapdata(tablewrapdata.fill);
 td.colspan = 2;
 formtext .setlayoutdata(td); 
 string text = "here is some plain text for the text to render; "+
   this text is at http://www.eclipse.org web site.";
 formtext .settext(text, false, true); 
  如果看我們的視圖,會是這樣:
 
圖16:form text組件將url自動轉化為超鏈接
  url被轉化為了鏈接.這個鏈接是包裹的文本中的一部分
  因為form text組件能夠識別超鏈接,因此它接收我們前面用過的監(jiān)聽器.當由toolkit創(chuàng)建時,form text會將toolkit的超鏈接組設置作為新超鏈接的設置.
新聞熱點
疑難解答