0

シェルのサイズ変更中にRowLayoutで問題が発生しました。コンポジットを作成し、そのコンポジットのレイアウトをRowLayoutとして設定しました。コンポジット内に3つのボタンを追加しました。シェルのサイズを変更するときに、3番目のボタンに十分なスペースがない場合は、シェルが下がるはずです。しかし、それは下がっていません。誰かがコードの何が悪いのか教えてもらえますか?以下の私のコードをご覧ください。

package com.rcp.mytraining.layout.composite;

import org.eclipse.swt.widgets.Composite;

public class ChatComposite extends Composite {

    /**
     * Create the composite.
     * 
     * @param parent
     * @param style
     */
    public ChatComposite(Composite parent, int style) {
        super(parent, style);

        Composite comp = new Composite(parent, SWT.NONE);
        // Color s = new Color(display, new RGB(30,30,30));

        Color s = Display.getDefault().getSystemColor(1);

        comp.setBackground(s);

        RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);

        rowLayout.wrap = true;
        rowLayout.pack = false;     

        comp.setLayout(rowLayout);

        Button btnNewButton = new Button(comp, SWT.NONE);
        btnNewButton.setText("New Button");

        Button btnNewButton_1 = new Button(comp, SWT.NONE);
        btnNewButton_1.setText("ss");

        Button btnNewButton_2 = new Button(comp, SWT.NONE);
        btnNewButton_2.setText("New Button");
        comp.pack();
    }

    @Override
    protected void checkSubclass() {
        // Disable the check that prevents subclassing of SWT components
    }

    public static void main(String[] args) {

        Display display = new Display();

        Shell shell = new Shell(display);

        // shell.setSize(200, 200);

        // shell.setLayout(new FillLayout());

        ChatComposite chatComposite = new ChatComposite(shell, SWT.NONE);


        shell.pack();
        shell.open();

        // chatComposite.pack();

        while (!shell.isDisposed()) {

            if (!display.readAndDispatch()) {

                display.sleep();
            }

        }
        // display.dispose();

    }

}

以下のコードの違いをご覧ください。同じように働きたかったのです。上記のコードは、以下のコードと同じように機能するはずです

package com.rcp.mytraining.layout.composite;

import org.eclipse.swt.widgets.Composite;

public class ChatComposite extends Composite {

    /**
     * Create the composite.
     * 
     * @param parent
     * @param style
     */
    public ChatComposite(Composite parent, int style) {
        super(parent, style);

        /*
         * RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
         * 
         * // rowLayout.wrap = true; //rowLayout.pack = true;
         * setLayout(rowLayout);
         * 
         * Button btnNewButton = new Button(this, SWT.NONE);
         * btnNewButton.setText("New Button");
         * 
         * Button btnNewButton_1 = new Button(this, SWT.NONE);
         * btnNewButton_1.setText("New Button");
         * 
         * Button btnNewButton_2 = new Button(this, SWT.NONE);
         * btnNewButton_2.setText("New Button");
         */

        pack();

    }

    @Override
    protected void checkSubclass() {
        // Disable the check that prevents subclassing of SWT components
    }

    public static void main(String[] args) {

        Display display = new Display();

        Shell shell = new Shell(display);

        // shell.setSize(200, 200);

        shell.setLayout(new FillLayout());

        Composite comp = new Composite(shell, SWT.NONE);
        // Color s = new Color(display, new RGB(30,30,30));

        Color s = Display.getDefault().getSystemColor(1);

        comp.setBackground(s);

        RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);

        rowLayout.wrap = true;
        // rowLayout.pack = true;
        comp.setLayout(rowLayout);

        Button btnNewButton = new Button(comp, SWT.NONE);
        btnNewButton.setText("New Button");

        Button btnNewButton_1 = new Button(comp, SWT.NONE);
        btnNewButton_1.setText("ss");

        Button btnNewButton_2 = new Button(comp, SWT.NONE);
        btnNewButton_2.setText("New Button");
        comp.pack();

        // ChatComposite chatComposite = new ChatComposite(shell, SWT.NONE);

        shell.pack();
        shell.open();

        // chatComposite.pack();

        while (!shell.isDisposed()) {

            if (!display.readAndDispatch()) {

                display.sleep();
            }

        }
        // display.dispose();

    }

}
4

1 に答える 1

1

指定しなかったため、コンポジットはシェルでサイズ変更されていません。

次のように、オブジェクトをレイアウトデータに追加しGridDataます。

comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

注:デバッグの目的で、の背景compを赤(またはその他の派手な色)に設定して、違いを確認することができます。

于 2013-01-22T10:30:22.847 に答える