Reputation: 1269
I have a subclass of Composite
that creates N number of combo boxes, where N is defined by an input. So when a user makes a change the number of combo boxes can potentially change. At the moment, this doesn't happen. I've tried two ways of doing this:
// On event, straight reconstruct, no change to number of dropdowns
myComp = new MyComposite(parent, SWT.NONE, newNum);
// On event, dispose and reconstruct, this completely removes my composite from the gui
myComp.dispose();
myComp = new MyComposite(parent, SWT.NONE, newNum);
Here is my Composite class:
public MyComposite(Composite parent, int num) {
super(parent, SWT.BORDER);
this.setText("MY Composite");
this.setLayout(new GridLayout(1, true));
this.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
combos = new HashMap<>();
for(int i = 0; i < num; i++) {
combos.put(i, new Combo(this, SWT.NONE));
}
}
Is there another/better way to do this?
Upvotes: 0
Views: 185
Reputation: 111142
If you change the contents of a Composite
you need to tell it you layout its contents again.
So after
myComp.dispose();
myComp = new MyComposite(parent, SWT.NONE, newNum);
you need to do
parent.layout(true, true);
Upvotes: 2