我有一个复合材料,我在启动视图时创建了五个文本框。点击按钮,我想用组合框替换第4个文本框。问题是我无法从头开始重新加载页面,因为我想显示文本框的当前值。
这是一个片段。
public class DisposeDemo {
private static void addControls(Shell shell) {
shell.setLayout(new GridLayout());
Text textOne=new Text(shell, SWT.BORDER);
Text textTwo=new Text(shell, SWT.BORDER);
Text textThree=new Text(shell, SWT.BORDER);
Text textFour=new Text(shell, SWT.BORDER);
Text textFive=new Text(shell, SWT.BORDER);
Button button = new Button(shell, SWT.PUSH);
button.setText("Replace text with Combo");
button.addSelectionListener(new SelectionAdapter() {
@Override public void widgetSelected(SelectionEvent event) {
//What code should go here to Replace the textFour with a combo
}
});
shell.pack();
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
addControls(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
答案 0 :(得分:0)
不是尝试替换控件(这很棘手)而是在开始时创建所有控件,但使其中一个不可见并将其从布局中排除。然后,您可以稍后切换可见性。
创建使用时:
<myloading ng-show="isLoad"></myloading>
要切换为可见组合:
Text textFour = new Text(shell, SWT.BORDER);
GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
textFour.setLayoutData(textFour);
Combo comboFour = new Combo(shell, ... style ...);
comboFour.setVisible(false); // Not visible
data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
data.exclude = true; // Exclude from layout
comboFour.setLayoutData(data);