Java:表单布局参数的说明



我在我的一个类中定义了以下摆动布局,但我无法弄清楚发生了什么。

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"));

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

您的布局有 5 列和 3 行。你可以从例子中很好地推断出这一点。

相关内容

  • 没有找到相关文章

最新更新