Estou construindo uma classe que extende a org.eclipse.swt.widgets.Composite, tendo como atributos de classe um botao e dois Composites faceUm e faceDois
O construtor recebe o parent (Composite) e os dois composites que são faces. O botão tem a função de mudar a face ativa (entre 1 e 2)
O meu problema é que não consigo ocultar uma face e mostrar a outra de forma a aparecer apenas o botão e uma face, sendo que a face ativa ocupe todo o espaço (exceto a linha onde está o botão). Veja o fonte abaixo:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
public class DoubleFacePanel extends Composite {
public static final int FACE_ONE = 1;
public static final int FACE_TWO = 2;
private Button btChangFace;
private Composite faceOne;
private Composite faceTwo;
private int currentFace;
public DoubleFacePanel(Composite parent, Composite faceOne, Composite faceTwo) {
super(parent, SWT.NONE);
setLayout(new GridLayout(1, true));
GridData gdData= new GridData(SWT.FILL, SWT.FILL, true, true);
btChangFace = new Button(this, SWT.NONE);
btChangFace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
changeFace();
}
});
btChangFace.setText("Change Face");
faceOne.setParent(this);
this.faceOne = faceOne;
this.faceOne.setLayoutData(gdData);
faceTwo.setParent(this);
this.faceTwo = faceTwo;
this.faceTwo.setLayoutData(gdData);
this.faceTwo.setVisible(false);
currentFace = FACE_ONE;
}
public int getCurrentFace(){
return currentFace;
}
public void changeFace(){
if(currentFace == FACE_ONE){
faceOne.setVisible(false);
faceTwo.setVisible(true);
currentFace = FACE_TWO;
}else{
faceOne.setVisible(true);
faceTwo.setVisible(false);
currentFace = FACE_ONE;
}
}
}
Como resolver esse problema? Como fazer a face ativa ocupar todo o espaço que cabe a ela?