如何在eclipse插件中定位组件?

时间:2012-12-25 09:56:20

标签: java eclipse eclipse-rcp eclipse-plugin

鉴于Eclipse视图中给出的默认容器,我希望定位一个AWT框架和一个SWT标签。我希望SWT标签位于顶部,AWT框架位于其下方。出于某种原因,我无法在框架所在的位置之外绘制SWT标签。我希望它们是分开的,但RowLayout似乎并没有将组件放入隔离的行中。

SWT标签不合需要地放在AWT框架内: enter image description here

插件视图中的代码:

public void createPartControl(Composite parent) {

    container = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
    RowLayout rowLayout = new RowLayout();
    //I have tried toggling many of the RowLayout properties but this has no effect on placing the label outside of the AWT Frame.
    container.setLayout(rowLayout);

    Label topLabel = new Label(container, SWT.NONE);
    topLabel.setText("MY NEW LABEL");

    frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(container);
    frame.setFocusable(true);
    frame.setFocusableWindowState(true);

1 个答案:

答案 0 :(得分:2)

RowLayout 从不将组件放入单独的行,它将它们放入一个行。您可以使用SWT.VERTICAL样式创建它,以便行从上到下而不是从左到右。但是,屏幕截图仍然不正确。将框架作为其自身复合材料的唯一子框架可能会有所帮助:

container = new Composite(parent, SWT.NONE);
RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
container.setLayout(rowLayout);

Label topLabel = new Label(container, SWT.NONE);
topLabel.setText("MY NEW LABEL");

Composite frameContainer = new Composite(container, SWT.EMBEDDED | SWT.NO_BACKGROUND);
frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(frameContainer);
frame.setFocusable(true);
frame.setFocusableWindowState(true);