2

In IntelliJ form is designed in special editor and saved in two files: *.java file and *.form file.

Here is the entire code of the application:

import javax.swing.*;

public class Test02 {
   private JButton button1Button;
   private JButton button2Button;
   private JButton button3Button;
   private JPanel mainPanel;


   public static void main(String[] args) {

      JFrame frame = new JFrame();
      frame.setContentPane(new Test02().mainPanel);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);

   }

}

If I run it, the following Window appear:

enter image description here

I.e. buttons got names and locations inside layout manager, according to data int *.form file.

How can it be?

No any initialization code, no any coordinates, no any reference to form file.

Where is *.form file read?

Dims
  • 47,675
  • 117
  • 331
  • 600
  • Looks like IntelliJ is doing magic here. It can use the Java file and the form file (which is just an XML file under the covers) to [generate the correct output](https://www.jetbrains.com/help/idea/2016.1/gui-designer-output-options.html?origin=old_help). I suspect these two files would be useless outside of IntelliJ's GUI designer. – Trisha Apr 12 '16 at 19:54
  • How would one design production apps then??? – Dims Apr 12 '16 at 19:57
  • Reading the info in the link, IntelliJ can generate all the source code, or skip straight to generating classes. The classes can be run in production, or the generated source code can be compiled and then run. The two files you're talking about are source code (not the output of a compiler), so would never be used in production anyway. – Trisha Apr 12 '16 at 20:01
  • Off course I will compile them before use in production. But how will they work? – Dims Apr 12 '16 at 20:11
  • Try generating the output as Java source code to see what that creates, that might give you an idea of how it works. – Trisha Apr 12 '16 at 20:16
  • Some class files for `uiDesigner` is created. But how are they activated? – Dims Apr 13 '16 at 11:13
  • Class files aren't the same as Java files, according to that documentation it's possible to generate as Java source files, which should be platform-independent. What happens when you output as Java source files instead of class files? – Trisha Apr 14 '16 at 10:20
  • It put some initialization code to source file. – Dims Apr 14 '16 at 11:29

0 Answers0