0

シェル要素の下に複合要素を追加しようとしましたが、ボタン ウィジェットが表示されません。何か不足していますか?

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class RadioButtonDemo {

    /**
     * Create radio buttons
     * 
     * @param parent
     *            Parent widget
     * @param labels
     *            Array of labels for the radio buttons
     * @param defaultSelection
     *            The default button to select
     * @return The newly created buttons complete with labels
     */
    public final Button[] getRadioButtons(final Composite parent,
            final String[] labels, int defaultSelection) {
        // some sanity stuff
        assert (defaultSelection < labels.length);
        assert (!parent.equals(null));

        final Button[] buttons = new Button[labels.length];
        for (int i = 0; i < buttons.length; i++) {
            buttons[i] = new Button(parent, SWT.RADIO);
            buttons[i].setText(labels[i]);
            buttons[i].setSelection(defaultSelection == i);
        }

        return buttons;
    }

    public void showDemo() {
        // some setup
        final Display display = new Display();

        Shell shell = new Shell(display, SWT.DIALOG_TRIM);
        // shell.setLayout(new RowLayout());
        shell.setSize(new Point(200, 200)); // make it small for the demo
        shell.setText("Radio button demo");
        shell.setLayout(new FillLayout());

        Composite c = new Composite(shell, SWT.NONE);

        final String[] labels = new String[] {
                "Never delete code coverage launches from history",
                "Delete oldest code coverage launches from history" };
        final Button[] radioButtons = this.getRadioButtons(c, labels, 0);

        shell.pack(); // min-size...
        shell.open(); // open shell

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }

        display.dispose(); // cleanup
    }

    public static void main(String[] args) {
        // new instance
        RadioButtonDemo instance = new RadioButtonDemo();
        instance.showDemo();

    }
}
4

1 に答える 1

1

にレイアウトを設定する必要がありますc

Composite c = new Composite(shell, SWT.NONE);
c.setLayout(new FillLayout());
于 2013-02-11T15:41:26.977 に答える