我对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;
}
}
答案 0 :(得分:2)
只需将IDEA_HOME\redist\forms_rt.jar
文件添加到module dependencies。
您可以关闭源代码生成,并使用GUI Designer的默认选项,它将检测字节码,以便您根本无法在编辑器中看到生成的代码。