Java MigLayout非法约束“码头”

时间:2018-09-28 09:44:36

标签: java layout-manager miglayout

我正在尝试创建一个按钮,并使用布局管理器将按钮停靠在面板的右侧,但是出现错误:

  

线程“主”中的异常java.lang.IllegalArgumentException:非法   约束:“码头”未知关键字。

package testpackage;

import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

public class MigPanel {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    MigLayout migLayout = new MigLayout();
    Dimension panelDimension = new Dimension(500,500);
    Dimension frameDimension = new Dimension(1000,1000);

    JButton submitButton = new JButton();
    Dimension buttonDimension = new Dimension(30,30);

    JButton submitButton2 = new JButton();
    Dimension buttonDimension2 = new Dimension(30,30);
    public MigPanel() {
        this.createLayout();
        this.createButton();
    }
    private void createLayout() {
        this.frame.add(this.panel);
        this.frame.setMinimumSize(frameDimension);
        this.frame.setVisible(true);

        this.panel.setLayout(migLayout);
        this.panel.setMinimumSize(panelDimension);
        this.panel.setVisible(true);
    }
    public void createButton() {
        this.submitButton.setSize(buttonDimension);
        this.submitButton.setVisible(true);
        this.panel.add(submitButton, "dock right");
    }
    public void setPanelVisible() {
        this.panel.setVisible(true);
    }

    public static void main(String[] args) {
        MigPanel migPanel = new MigPanel();
    }
}

1 个答案:

答案 0 :(得分:2)

您使用了错误的约束。更改

  this.panel.add(submitButton, "dock right");

  this.panel.add(submitButton, "dock east");

为进一步阅读,我建议这样做:QuickStart