【问题标题】:Java: Explanation of form layout parameters [closed]Java:表单布局参数的解释[关闭]
【发布时间】:2012-12-17 22:10:24
【问题描述】:

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

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

【问题讨论】:

标签: java swing layout layout-manager form-layout


【解决方案1】:

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

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

【讨论】:

  • 更准确地说,它有3行,由3dlu的垂直空间分隔,所以你也可以说它有5行
猜你喜欢
  • 2011-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-30
  • 1970-01-01
相关资源
最近更新 更多