JFace,SWT更改输入时更改组合查看器宽度

时间:2016-01-02 11:20:20

标签: java swt jface

我有两个comboviewer,其想法是第二个组合将根据所选的第一个组合值显示一个选项子集。但是在第二个组合中设置新输入后刷新组合宽度太小。如何将其设置为自动调整到选项宽度?

public class ExpresionDialog extends Dialog {
    private ComboViewer combo1;
    private ComboViewer combo2;

    @Override
    protected Control createDialogArea(Composite composite) {
        Composite parent = (Composite) super.createDialogArea(composite);
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);

        combo1 = new ComboViewer(parent);
        combo1.setLabelProvider(new LabelProvider());
        combo1.setContentProvider(ArrayContentProvider.getInstance());
        combo1.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent e) {
                IStructuredSelection sel = (IStructuredSelection) e.getSelection();
                AttributeOption option = (AttributeOption) sel.getFirstElement();
                combo2.setInput(getValuesCombo2(option));
                combo2.refresh(true);
            }
        });
        combo1.setInput(getValuesCombo1());

        combo2 = new ComboViewer(parent);
        combo2.setLabelProvider(new LabelProvider());
        combo2.setContentProvider(ArrayContentProvider.getInstance());

        return parent;
    }

// Omitted getValuesCombo1 and getValuesCombo2 methods ...
}

1 个答案:

答案 0 :(得分:1)

您需要调用父layout的{​​{1}}方法,以便在每次更改内容时重做子布局。