我是swt的新手。在eclipse插件中,我创建了包含一些代码的视图,如下所示。
public void createPartControl(final Composite parent) {
Composite outer = new Composite(parent, SWT.BORDER);
outer.setBackground(new Color(null, 207, 255, 206)); // Green
FormLayout formLayout = new FormLayout();
formLayout.marginHeight = 5;
formLayout.marginWidth = 5;
formLayout.spacing = 5;
outer.setLayout(formLayout);
//TOP
Composite Top = new Composite(outer, SWT.BORDER);
Top.setLayout(new GridLayout());
Top.setBackground(new Color(null, 232, 223, 255)); // Blue
FormData fData = new FormData();
fData.top = new FormAttachment(0);
fData.left = new FormAttachment(0);
fData.right = new FormAttachment(100); // Locks on 10% of the view
fData.bottom = new FormAttachment(20);
Top.setLayoutData(fData);
//BOTTOM
Composite Bottom = new Composite(outer, SWT.BORDER);
Bottom.setLayout(fillLayout);
Bottom.setBackground(new Color(null, 255, 235, 223)); // Orange
fData = new FormData();
fData.top = new FormAttachment(20);
fData.left = new FormAttachment(0);
fData.right = new FormAttachment(100);
fData.bottom = new FormAttachment(100);
Bottom.setLayoutData(fData);
Bottom Composite包含一些标签,在mouseListener的mouseDown上,应该重绘整个页面。我使用了dispose,但页面是空的,但它不再创建。如何重绘或刷新主要父级。
标签代码如下所示:
Label label = new Label(Bottom, SWT.NONE);
label.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent arg0) {
}
@Override
public void mouseDown(MouseEvent arg0) {
for (Control kid : parent.getChildren()) {
kid.dispose();
}
//Need to create/redraw th layout here
}
@Override
public void mouseDoubleClick(MouseEvent arg0) {
}
});
答案 0 :(得分:0)
在父Composite上调用layout()方法