User1990
User1990

Reputation: 85

Intellij giving me an error when it builds project from gui form

I'm somewhat new to Java and using intellij to learn gui. If I understand right, intellij doesn't build the source code for your gui when you design it, you have to select build->buildproject. It auto generates the code but provides things that give me an error in my code. Everywhere this shows up "com.intellij.uiDesigner.core.GridConstraints", it's red in the editor.

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

Upvotes: 1

Views: 2357

Answers (2)

Artur Łysik
Artur Łysik

Reputation: 437

For those using maven, adding dependency helps:

<dependency>
    <groupId>com.intellij</groupId>
    <artifactId>forms_rt</artifactId>
    <version>7.0.3</version>
</dependency>

Upvotes: 3

CrazyCoder
CrazyCoder

Reputation: 401887

Just add IDEA_HOME\redist\forms_rt.jar file to the module dependencies.

You can switch off source code generation and use the default option for GUI Designer which will instrument the bytecode so that you don't see the generated code at all in the editor.

Upvotes: 3

Related Questions