Eclipse Form設計指南之定製布局

來源:互聯網
上載者:User

3、定製布局

Eclipse Form提供了2個新的布局

(1)TableWrapLayout

·問題:如果將上例中超連結的文本設定的足夠長

link.setText("This is an example of a form that is much longer and will need to wrap.");

即使設定了SWT.WRAP,常值內容不會自動WRAP,這是因為體內容的布局是GridLayout

·Eclipse Form提供替代的布局TableWrapLayout:類似於GridLayout,但是具有象HTML表格一樣自動WRAP功能

·下面是解決超連結文本自動WRAP的例子:

public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
form.setText("Hello, Eclipse Forms");

Composite body = form.getBody();
TableWrapLayout layout = new TableWrapLayout();
body.setLayout(layout);
Hyperlink link = toolkit.createHyperlink(body, "Click here.", SWT.WRAP);
link.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
System.out.println("Link activated!");
}
});

layout.numColumns = 2;
link.setText("This is an example of a form that is much longer and will need to wrap.");
TableWrapData td = new TableWrapData();
td.colspan = 2;
link.setLayoutData(td);
Label label = toolkit.createLabel(body, "Text field label:");
Text text = toolkit.createText(body, "");
td = new TableWrapData(TableWrapData.FILL_GRAB);
text.setLayoutData(td);
text.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
Button button = toolkit.createButton(body,"An example of a checkbox in a form", SWT.CHECK);
td = new TableWrapData();
td.colspan = 2;
button.setLayoutData(td);
toolkit.paintBordersFor(body);
}

·下面是程式變化的地方:

1) TableWrapLayout替代GridLayout

2) 使用TableWrapData來提供布局資料資訊

3) 設定的屬性使用colspan、rowspan等來源於HTML表格單元的屬性

·要注意的是:需要自動WRAP的控制項,需要設定成SWT.WRAP風格

(2)ColumnLayout

·ColumnLayout是Eclipse Form提供的另一個定製布局

·ColumnLayout的布局方式是從上到下,從左至右

·在變化Form的寬度時,會自動調整控制項列數以適應Form的寬度

·ColumnLayout的設定很簡單,通常只要設定列數的範圍(預設是1-3)

·在後面的相關部分會給出使用的例子

文章來自: 好喜愛學習網(http://www.haoxiai.net) 網址:http://www.haoxiai.net/bianchengyuyan/jspjiaocheng/59014.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.