gpt4 book ai didi

Java MigLayout非法约束 'dock'

转载 作者:行者123 更新时间:2023-12-02 01:54:11 27 4
gpt4 key购买 nike

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

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 .

关于Java MigLayout非法约束 'dock',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52552561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com