我在Eclipse RCP应用程序中创建了一个简单的SWT容器,并且在显示它的位置/顺序时遇到问题。这是我正在使用的代码。RCP的SWT复合显示中的问题
@PostConstruct
public void createControls(Composite parent)
{
parent.setBackground(new Color (Display.getCurrent(), 255, 144, 0));
GridData parentData = new GridData(SWT.FILL, SWT.FILL, true, true);
parent.setLayout(new GridLayout(1, true));
parent.setLayoutData(parentData);
Device device = Display.getCurrent();
Color backgroundColor = parent.getBackground();
Color whiteColor = new Color (device, 255, 255, 255);
Color randomColor = new Color (device, 255, 0, 0);
final Composite criteriaContainer = new Composite(parent, SWT.BORDER);
criteriaContainer.setBackground(randomColor);
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
final GridData comboGridData = new GridData(SWT.FILL, SWT.TOP, true, false,1,1);
criteriaContainer.setLayout(new GridLayout(1, false));
criteriaContainer.setLayoutData(gridData);
final Label primaryComboLabel = new Label(criteriaContainer, SWT.NONE);
primaryComboLabel.setLayoutData(comboGridData);
primaryComboLabel.setForeground(whiteColor);
primaryComboLabel.setText("View by:");
criteriaContainer.layout();
criteriaContainer.pack();
parent.layout();
parent.pack();
}
我不能似乎得到的标签出现在应用程序的顶部(底部出现中心)在这里输入的形象描述] [1]。如果我编写相同的代码并将其作为独立的SWT应用程序执行,则标签将显示在左上角。 [1]:http://i.stack.imgur.com/OL312.png 下面是我有独立的SWT应用程序时的区别。
public void showHistoryContainer() throws Exception {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setBackground(new Color (Display.getCurrent(), 255, 144, 0));
其余的代码是一样的。 [2]:http://i.stack.imgur.com/fJmR6.png
任何想法,为什么会发生这种情况?
注意:在我的RCP应用程序中,我没有对我的父级组合进行任何其他处理。
感谢您的指点。我不打算使用Color,我只是用它看到容器,为什么他们不在正确的位置。 (尽管我不知道如何处理它们,谢谢)是的,createControls是一个MPart。我试过你的代码,我的容器仍然从底部出现。仍然不知道为什么会发生这种情况 –
所以我想出了问题。我没有发布代码,因为我正在查看错误的类,并且我认为它没有做任何事情,但是我将父项传递给另一个将画布添加到其中的方法。对不起菜鸟的错误,但感谢有用的指针。 –