我对 Java 有点陌生,并且使用 intellij 来学习 gui。如果我理解正确的话,当你设计它时,intellij不会为你的gui构建源代码,你必须选择build->buildproject。它会自动生成代码,但会提供一些导致我的代码出错的信息。在任何显示“com.intellij.uiDesigner.core.GridConstraints”的地方,它在编辑器中都是红色的。
import javax.swing.*;
import java.awt.*;
public class GameGUI {
private JPanel contolPanel;
private JLabel labelImage;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contolPanel = new JPanel();
contolPanel.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
contolPanel.setAlignmentX(1.0f);
contolPanel.setAlignmentY(1.0f);
contolPanel.setAutoscrolls(false);
contolPanel.putClientProperty("html.disable", Boolean.FALSE);
labelImage = new JLabel();
labelImage.setIcon(new ImageIcon(getClass().getResource("/images/java.png")));
labelImage.setText("Label");
contolPanel.add(labelImage, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final com.intellij.uiDesigner.core.Spacer spacer1 = new com.intellij.uiDesigner.core.Spacer();
contolPanel.add(spacer1, new com.intellij.uiDesigner.core.GridConstraints(0, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return contolPanel;
}
}
最佳答案
只需将 IDEA_HOME\redist\forms_rt.jar
文件添加到 module dependencies .
您可以关闭源代码生成并使用 GUI 设计器的默认选项,该选项将检测字节码,以便您在编辑器中根本看不到生成的代码。
关于java - Intellij 从 gui 表单构建项目时给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56636795/