GUI Designer - Where I will find the generated code?

Answered

Hello,

I try to use the GUI Designer of IntelliJ IDEA 2016.1.2 an d I have read https://www.jetbrains.com/help/idea/2016.1/gui-designer.html 
"Binary class files. This is the default option. When selected, no Java source code is generated for GUI forms and components. When the project compiles, IntelliJ IDEA simply creates the necessary compiled runtime classes.

  • "Java source files.If this option is selected, the GUI Designer writes Java source code for the form and its components to the source file of the class to which the form is bound, on compiling, running or debugging. During compilation, two blocks of code are added to the form's class:
    • A private method $$$setupUI$$$() that contains the GUI initializer code for the bound form and its components.
    • A call to the $$$setupUI$$$() method."
When I start a new class TestForm with GUIForm then I will get two files "TestForm.java" and "TestForm.form". In last is the xml-code of the class. But in the class TestForm.java I don't find the code of my build gui like

contentPane.setLayout(new GridBagLayout());
((GridBagLayout)contentPane.getLayout()).columnWidths = new int[] {133, 47, 0, 0, 0};

Instead I see only 
public class TestForm {
private JTextField textField1;
private JPanel panel1;

private void createUIComponents() {
// TODO: place custom component creation code here
}
}

Where is

Java source files.If this option is selected, the GUI Designer writes Java source code for the form and its components to the source file of the class
realized?

Can you explain me, what I do wrong?

Best regards

Andreas

 

3
16 comments

Are you sure you have enabled this option?

0
Avatar
Permanently deleted user

Yes, how I said. Here's my setting for it:

0

Use Build | Make, generated code will appear in the source file (in a section collapsed by default).

If the issue remains, please provide a sample project illustrating the problem and the exact steps to reproduce.

1
Avatar
Permanently deleted user

Thanks Serge, it runs:

public class testForm {
private JButton button1;

{
// 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$$$() {
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridBagLayout());
button1 = new JButton();
button1.setText("Button");
GridBagConstraints gbc;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel1.add(button1, gbc);
final JPanel spacer1 = new JPanel();
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel1.add(spacer1, gbc);
final JPanel spacer2 = new JPanel();
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.VERTICAL;
panel1.add(spacer2, gbc);
}
}
0
Avatar
Permanently deleted user

Hi Serge, what do you mean by "Build|Make"? Is "Make" supposed to be an option in the "Build" menu? This is what mine looks like:

0

It was renamed to Build | Build several years ago.

1
Avatar
Permanently deleted user

Okay, I built it but I still can't seem to find the source code. You stated that it's in "a section collapsed by default" so I clicked every button for collapsible menus and files that I could find, but it's still not coming up.

0

File a bug at https://youtrack.jetbrains.com/issues/IDEA and attach a sample project to reproduce this issue.

0
Avatar
Permanently deleted user

UPDATE: I found some source code in the affiliated ".java" file, but if I open the ".form" file in notepad, I get an .xml file. I haven't seen any mention of xml with GUI though...

(Sorry, I promise this is the last question)

0

It's by design, source code is generated from the xml .form file.

2

Serge Baranov the issues occurs at the my example project https://github.com/Kolyall/GUIExample

Idea version
IntelliJ IDEA 2019.3.2 (Community Edition)
Build #IC-193.6015.39, built on January 21, 2020
Runtime version: 11.0.5+10-b520.30 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 5.3.0-26-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1921M
Cores: 12
Registry:
Non-Bundled Plugins: mobi.hsz.idea.gitignore

0

Thank you for posting the issue on our tracker, we will shortly deal with it.

0

I tried UI Designer with Gradle, and It didn't work. So I created a new Maven project and, voila, it worked.

0

Please sign in to leave a comment.