0

私のクラスの 1 つで次のスイング レイアウトが定義されていますが、何が起こっているのかわかりません。

private void initComponents()
    {
        locationPanel = new JPanel();
        label1 = new JLabel();
        lastUpdateLabel = new JLabel();
        label2 = new JLabel();
        accuracyLabel = new JLabel();
        batteryPanel = new JPanel();
        batteryLabel = new JLabel();
        label3 = new JLabel();
        cc = new CellConstraints();

        setLayout(new FormLayout("default", "default"));

        locationPanel.setBorder(new TitledBorder("Info"));
        locationPanel.setLayout(new FormLayout("right:pref, 6dlu, 50dlu, 4dlu, default", "pref, 3dlu, pref, 3dlu, pref"));


        label1.setText("Last Update:");
        locationPanel.add(label1, cc.xy(1, 1));

        lastUpdateLabel.setText("Unknown");
        locationPanel.add(lastUpdateLabel, cc.xy(3, 1));


        label2.setText("Accuracy:");
        locationPanel.add(label2, cc.xy(1, 3));

        // ---- accuracyLabel ----
        accuracyLabel.setText("Unknown");
        locationPanel.add(accuracyLabel, cc.xy(3, 3));

        label3.setText("Battery Level");
        locationPanel.add(label3, cc.xy(1, 5));


        batteryLabel.setText("Unknown");
        locationPanel.add(batteryLabel, cc.xy(3, 5));

        add(locationPanel, cc.xy(1, 1));
    }

質問: 3 行 2 列にすべきだと言っていると思いますか? 定義されている行と列の数。4 x 2 のレイアウトを作成するにはどうすればよいですか? これが何を言っているのかをどのように判断しますか locationPanel.setLayout(new FormLayout("right:pref, 6dlu, 50dlu, 4dlu, default", "pref, 3dlu, pref, 3dlu, pref"));

4

1 に答える 1

2

http://www.java2s.com/Code/Java/Swing-Components/FormLayoutExplicitAlignmentExample3.htm

あなたのレイアウトには5列と3行があります。例からそれを推測することができます。

于 2012-12-17T22:23:32.007 に答える