0

私は最初のユーザー インターフェイスを完全に手作業でコードから設計しています (「ドラッグ アンド ドロップ」IDE は使用しません)。

したがって、あるフォームで問題が発生しました。私のレイアウトのスクリーンショットでわかるように: 私のフォームレイアウト

赤色の textFields は From ラジオ ボタンと位置合わせされていません。青のテキストフィールドがラベル「To:」と整列していないという同じ問題。それらは 1 行で整列されていないように見えますがgridy、"From:" ラジオ ボタンと "To:" ラベルで に同じ値を使用しています。

緑色のものも少しずれています。

コード全体を調べましたが、どこが間違っているのかわかりません。誰かがそれらを適切に整列させるのを手伝ってくれますか?

編集

public void layoutComponents()
{
    //add to the layout (what is above )
    setLayout(new GridBagLayout());
    GridBagConstraints gc = new GridBagConstraints(); //class that specifies where goes what we want



    ////////// Insert and Align Labels and Fields //////////


    gc.weightx = 1; // how much space it takes relatively to other cells
    gc.weighty = 1; // how much space it takes relatively to other cells
    gc.fill = GridBagConstraints.NONE;

    //specify to wich side it will stick to
    gc.anchor = GridBagConstraints.LINE_START; // stick to the right hand side

    Insets fivePixels = new Insets(0, 0, 0, 5);// adds 5 pixels of spcae to the right
    Insets zeroPixels = new Insets(0, 0, 0, 0);

    gc.gridx = 0;
    gc.gridy = 0; //y increase downwards
    gc.insets = fivePixels;
    add(dataSourceBoldLabel, gc);

    gc.gridy = 1; //second row
    add(sourceTableLabel, gc);

    gc.gridy = 2;
    add(processDataPeriodLabel, gc);

    gc.gridy = 5;
    add(resultsBoldLabel, gc);

    gc.gridy = 6;
    add(writeResultsToNewTableRadio,gc);

    gc.gridy = 7;
    add(writeResultsToExistingTableRadio, gc);

    gc.gridy = 8;
    add(processDataOptionsLabel, gc);

    gc.gridy = 9;
    add(accessSessionTimeThresholdLabelLabel, gc);

    gc.gridy = 10;
    add(transitionTimeThresholdLabelLabel, gc);







    ///////////     Second Column  X = 1     ////////////


    gc.insets = zeroPixels;
    gc.gridx = 1;


    gc.gridy = 1;
    add(sourceTables, gc);

    gc.gridy = 2;
    add(allRadio, gc);

    gc.gridy = 3;
    add(fromRadio, gc);

    gc.gridy = 4;
    gc.anchor = GridBagConstraints.LINE_END;
    add(toLabel, gc);

    gc.anchor = GridBagConstraints.NORTHWEST;
    gc.gridy = 6;
    add(newTableField, gc);

    gc.gridy = 7;
    add(resultsTables, gc);

    gc.gridy = 9;
    add(accessSessionTimeThresholdField,gc);

    gc.gridy = 10;
    add(transitionTimeThresholdField, gc);

    gc.anchor = GridBagConstraints.NORTHWEST; //push the buttom to the top
    gc.gridy = 15;
    add(start, gc);



    ////////////////// Third Column    X = 2 //////////////////
    gc.gridx = 2;
    gc.gridy = 4;
    add(fromDateField, gc);

    gc.gridy = 5;
    add(toDateField, gc);





    ///////////////// 4th Column    X = 3 /////////////////////
    gc.gridx = 3;
    gc.gridy = 4;
    add(fromTimeField, gc);

    gc.gridy = 5;
    add(toTimeField, gc);


}

}

4

1 に答える 1