我正在设计一个jface / swt的GUI,我正在创建一个包含一个部分的滚动表单,在该部分内部有一个复合。 在该组合上,我添加了一个包含2个元素的组合查看器。 在选择第一个元素时,有2个小部件,一个是带文本框的标签,另一个是表。 在选择第二个元素时,只有一个小部件是带有文本框的标签。 现在,我的问题是,当我选择第二个元素时,它正在处理表,但表占用的空间仍然存在。
所以,如何在选择seconnd元素后删除不需要的空间。 请帮帮我。
这是我创建滚动表单的第一个函数
class Test extends FormDialog{
protected void createFormContent(IManagedForm managedform) {
toolkit = managedform.getToolkit();
scrolledForm = managedform.getForm();
Shell shell = scrolledForm.getShell();
shell.setText("First Form");
// I am using GridLayout and GridData.
scrolledForm.pack();
scrolledForm.reflow(true);
}
// After this there is a method containing section and a composite inside the section.
protected void createCombo(final Composite client) {
Label label1 = toolkit.createLabel(client,"First Label : ", SWT.NULL);
final ComboViewer comboViewer1 = new ComboViewer(client,SWT.NORMAL|SWT.NORMAL);
//In this Compoviewer1, I am adding 2 persons ie "ABC" and "XYZ".
comboViewer1.getCombo().select(0);
// Here I am Calling Two methods, createFirstContent() method contains label and comboviewer. And createSecondContent() method contains TableViewer which is created inside a Group
createFirstContent(client);
createSecondContent(client);
comboViewer1.addSelectionChangedListener(new ISelectionChangedListener(){
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event
.getSelection();
if(((Person) selection.getFirstElement()).getName().equals("ABC")){
createFirstContent(client);
createSecondContent(client);
}else if(((Person) selection.getFirstElement()).getName().equals("XYZ")){
if(tablegroup != null && !(tablegroup.isDisposed())){
tablegroup.dispose();
createFirstContent(client);
}
});
}
protected void createFirstContent(Composite clientComposite){
Label label = toolkit.createLabel(clientComposite,"First Lbl : ", SWT.NULL);
label .setLayoutData(new GridData(SWT.FILL, SWT.FILL,true, false));
ComboViewer combo = new ComboViewer(clientComposite, SWT.READ_ONLY | SWT.NORMAL);
}
protected void createSecondContent(Composite clientComposite) {
tablegroup = new Group(clientComposite, SWT.FILL);
tablegroup.setLayout(new GridLayout());
tablegroup.setText("Table Group");
createTableViewer(tablegroup);
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = false;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
tablegroup.setLayoutData(gridData);
}
protected void createTableViewer(Group tablegroup) {
viewer = new TableViewer(tablegroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
TableColumnLayout tcl = new TableColumnLayout();
createColumns(tcl);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
GridData gridData = new GridData(SWT.FILL, SWT.FILL,true, true;
gridData.horizontalSpan = 2;
viewer.getControl().setLayoutData(gridData);
}
在createColums()方法中,我正在创建表的列。
在所有这些事情之后,我正在创建另一个部分。并在该部分创建一些其他小部件。
但我的问题是,当我在选择XYZ时处理taht表时,表将被释放但表占用的空间不会被删除。 因此,两个部分之间将存在不必要的间隙/间隔。 请告诉我如何删除该空间。