How to use the GUI Designer to design a JFrame-derived class?
I'll preface this by saying I come from NetBeans, so I'm conceptually still stuck in that mode of thinking, nevertheless:
From what I understood, the way to create a Form in IDEA's GUI Designer is that I create the form and the bound class, I design my form in the form file, and then I code the rest in the class - I can follow thus far.
However, if I understood correctly, I'm then supposed to create a `public static void main()` that initializes the form, by (default) creating a JFrame and setting its contentPane to the root JPanel.
What if my class extends JFrame though, and I want to be able to instantiate it outside of the class? Say I've got MyFileDialog with some specifics. How can I design MyFileDialog in IDEA's GUI Designer and then be able to instantiate it as a variable (because it might need to be passed around, etc) from the rest of my project?
So far I've solved this by rewriting the `public static void main()` method to a `public static JFrame init()` which then returns the created JFrame, and I just call the static method to instantiate the JFrame and have it as a variable from outside, but this is so unintitive I feel I must be getting something wrong about the philosophy behind IDEA's GUI Designer.
What would be a "proper" way to do this?
Please sign in to leave a comment.
It's pretty common to make a class bound to a form that returns JPanel or JFrame and then use it where needed.
By "making a class bound to a form that returns JPanel/JFrame" - do you mean what I did, i.e. instead of building up the JFrame in the constructor, making a static method that returns an instance of the built-up JFrame?
It doesn't have to be static, something like new MyForm().getPanel();.