Java MigLayout 非法约束'dock'

Java MigLayout illegal constraint 'dock'

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

Exception in thread "main" java.lang.IllegalArgumentException: Illegal Constraint: 'dock' Unknown keyword.

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();
    }
}

您使用了错误的约束条件。变化

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

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

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