调整 Eclipse RCP 中子 UI 元素的大小
我有一个最初调整大小的 TabFolder。 TabFolder 下是一个 TabItem,该 TabItem 下是一个 Button。 Button 继承了 TabFolder 的大小,因此它很大。调整按钮大小的最佳方法是什么?使用button.setBounds(...) 不起作用。
这是代码片段:
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);
btnNewButton.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 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);
btnNewButton.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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案。我刚刚从选项卡的控件中删除了按钮。
已删除:
按钮现在可以独立调整大小,或者在使用空布局时使用 setBounds 调整大小。
I found a solution. I just removed the button from the control of the tab.
Removed:
The button can now be resized independently or using setBounds when using a null layout.
那么您在
TabItem
上设置的 Control 是一个Composite
吗?或者一个按钮
?控制按钮大小的方法是创建一个
Composite
并将其设置在TabItem
上。然后您可以将按钮添加到Composite
。然后,您可以在组合上设置布局来控制按钮的布局方式。请参阅 http://www.eclipse.org/ articles/article.php?file=Article-Understanding-Layouts/index.html 了解有关布局的更多详细信息。编辑:
要使用它,您可以在选项卡文件夹和按钮之间插入一个组合:
您使用布局来控制子控件的大小......在本例中是您的按钮。请参阅了解布局一文。
So the Control you set on
TabItem
was aComposite
? Or aButton
?The was to control the size of the button is to create a
Composite
and set that on theTabItem
. Then you can add your button(s) to theComposite
. 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:
You use layouts to control the sizes of child controls ... in this case, your button. See the Understanding Layouts article.