0

我在我的一个课程中定义了以下挥杆布局,但我无法弄清楚发生了什么。

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 回答