2016-08-03 16 views
0

私はN個のコンボボックスを作成するCompositeのサブクラスを持っています。ここでNは入力によって定義されます。したがって、ユーザーが変更を行うと、コンボボックスの数が変更される可能性があります。現時点では、これは起こりません。私はこれを行うための二つの方法を試してみた:ここswt - コンポジットを再作成

// 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); 

は私のコンポジットクラスです:

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)); 
    } 
} 

はこれを行うには、別の/より良い方法はありますか?

答えて

2

Compositeの内容を変更する場合は、内容を再度レイアウトする必要があります。

ので

myComp.dispose(); 
myComp = new MyComposite(parent, SWT.NONE, newNum); 

した後、あなたは

parent.layout(true, true); 
を行う必要があります
関連する問題