开发者

Resize child UI element in Eclipse RCP

I have a TabFolder which was resized initially. Under the TabFolder is a TabItem and under that TabItem is a Button. The Button inherited the size of the TabFolder so it's huge. What's the best way to resize the Button? Using button.setBounds(...) doesn't work.

Here is the code snippet:

public void createPartControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);

    TabFolder tabFolder = new TabFolder(container, SWT.NONE);
    Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize();



    TabItem tbtmNewItem = new TabItem(tabFolder, SWT.NONE);
    tbtmNewItem.setText("1");

    TabItem tbtmBrowse = new TabItem(tabFolder, SWT.NONE);
    tbtmBrowse.setText("3");

    Button btnNewButton = new Button(tabFolder, SWT.BORDER | SWT.CENTER);
    b开发者_StackOverflowtnNewButton.setAlignment(SWT.CENTER);
    tbtmBrowse.setControl(btnNewButton);
    btnNewButton.setText("Push");


    tabFolder.setBounds(0, 0,dim.width-10,dim.height-10);

    createActions();
    initializeToolBar();
    initializeMenu();
    this.setPartName("Home");


}


I found a solution. I just removed the button from the control of the tab.

Removed:

tbtmBrowse.setControl(btnNewButton);

The button can now be resized independently or using setBounds when using a null layout.


So the Control you set on TabItem was a Composite? Or a Button?

The was to control the size of the button is to create a Composite and set that on the TabItem. Then you can add your button(s) to the Composite. You then set a layout on the composite to control how your button(s) are laid out. See http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html for more details on layouts.

EDIT:

To use it, you insert a composite between the tab folder and the button:

Composite page = new Composite(tabFolder, SWT.NONE);
page.setLayout(new GridLayout(1, false));
Button btnNewButton = new Button(page, SWT.BORDER | SWT.CENTER);
btnNewButton.setAlignment(SWT.CENTER);
btnNewButton.setText("Push");
tbtmBrowse.setControl(page);

You use layouts to control the sizes of child controls ... in this case, your button. See the Understanding Layouts article.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜