我有一个带有动态子 Composite 的父 ScrolledComposite。当我删除一行时,使用 ScrolledComposite 时对齐会消失。我已经尝试使用 Composite 而不是 ScrolledComposite 并且它似乎可以工作,所以我想知道滚动布局是否没有正确更新。
附件是一些显示 1 个条目与 3 个条目的图像。感兴趣的区域是可移动环部分。单个条目时对齐明显不正确,但有 3 个条目时接近正常。下面的代码...
/**
* Create display area for movable rings.
*
* @param topComposite
*/
private void createMovableRingsComposite(Composite topComposite) {
new Label(topComposite, SWT.NONE).setText("Movable Rings");
Composite borderComposite = new Composite(topComposite, SWT.BORDER);
borderComposite.setLayout(new GridLayout(1, false));
borderComposite.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL));
scroll = new ScrolledComposite(borderComposite,SWT.V_SCROLL|SWT.BORDER);
GridLayout gridL = new GridLayout(1, false);
GridData gridD = new GridData(SWT.FILL,SWT.FILL,true,true);
gridD.heightHint = 200;
scroll.setLayout(gridL);
scroll.setLayoutData(gridD);
scroll.setAlwaysShowScrollBars(true);
scroll.setExpandHorizontal(true);
scroll.setExpandVertical(true);
movableRingsComposite = new Composite(scroll, SWT.NONE);
movableRingsComposite.setLayoutData(new GridData(SWT.CENTER,
SWT.CENTER, true, true, 1, 1));
movableRingsComposite.setLayout(new GridLayout(6, false));
// Make all the labels
new Label(movableRingsComposite, SWT.NONE).setText("Show");
new Label(movableRingsComposite, SWT.NONE).setText("ID");
new Label(movableRingsComposite, SWT.NONE).setText("Lat");
new Label(movableRingsComposite, SWT.NONE).setText("Lon");
new Label(movableRingsComposite, SWT.NONE).setText("Radius");
new Label(movableRingsComposite, SWT.NONE).setText("Labels");
scroll.setContent(movableRingsComposite);
Composite createComposite = new Composite(borderComposite, SWT.NONE);
createComposite.setLayout(new GridLayout(3, false));
createComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
true, true, 1, 1));
new Label(createComposite, SWT.NONE).setText("New at: ");
pointsMenuButton = new MenuButton(createComposite);
populatePointsMenuButton();
pointsDataManager.addPointsChangedListener(this);
pointsMenuButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MenuButton menuButton = (MenuButton) e.widget;
MenuItem mi = menuButton.getSelectedItem();
addMovableRing(mi.getText());
menuButton.setSelectedItem("Select One");
}
});
Button delete = new Button(createComposite, SWT.PUSH);
delete.setText("Delete");
delete.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
deleteMovableRing();
}
});
}
/**
* Remove the ring of the selected movable ring row.
*/
private void deleteMovableRing() {
for (MovableRingRow row : movableRings) {
if (row.isSelected()) {
row.dispose();
movableRings.remove(row);
movableRingsComposite.layout(true);
getShell().pack();
if (!movableRings.isEmpty()) {
movableRings.iterator().next().selectRow(true);
}
break;
}
}
}