How to initialize a Swing form created by the Intellij Designer? - java

I have to build multiple Swing forms and I thought to speed up the process by using the Form Designer provided by Intellij IDEA.
First of all, I've created a new GUI form.
Then I added some labels, text fields and a button to the form.
Now I want to add this form to another Panel. I've been checking out the Intellij help and I found this. Unfortunately it doesn't work like this. There is no accessible contentPane in this class, which is generated by the IDE.
What magic do I have to apply to get this to work?
Bonus question:
Usually I extend a Swing component. For example in that case I would have something like public class BullshitForm extends JPanel{}. Is this possible with the Intellij Designer?

Select the class BullshitForm press ALT + Insert and select Form main().

i have the exact same problem as you.
I found out that the problem is that i used gradle to build my project.
After the switch to maven, everythings working now.
It seems that the gradle build process did not implement the initialication of the gui controls.

Related

How to edit automatically generated code by netbeans desing UI?

I have this Afficheur java class in my project (its a DrawingPanel) which takes a MainWindow object in parameter. MainWindow is essentially a swing UI which Netbeans automatically generated code for as I designed it with their desing tool.
In order for it to work I have to edit this generated code by Netbeans and add 'this' in parameter to Afficheur when I create a new Afficheur (see line 85), which only is possible when I edit the code in notepad.
This method makes my code work but as soon as I try to modify the UI with the netbeans design tool the whole thing messes up. I know this is the issue because I tried removing 'this' and then modifying my UI and then adding 'this' back and everything worked fine. Its like netbeans can't generate code properly when I have modified its code. Any Idea on how I can resolve this issue?
Just go to the design tab and then right click on the item you want to change the code of and then click customize code (or something like that, i don't remember correctly) and edit the code.

Initialize GUI components in IntelliJ

I'm currently building my first GUI with IntelliJ. I arranged all my components in the GUI Designer unisng a Grid-Bag-Layout. My problem is that in the bound class, no code gets generated to make the application actually look like what I designed, there are only declarations of the different components. According to this tutorial said code should be automatically generated when compiling the project and processed to the .class file. But that doesn't seem to happen, as I only get an empty window when compiling and running my project.
Alright I figured it out. Apparently the JPanel which contains all the components doesn't get added to the JFrame by default. So I had to manually call add(panel) in my constructor.

How should I efficiently update a Swing GUI?

I created a program with a Swing GUI in NetBeans a while back using the Graphical Editor. I now needed a web version but since I use eclipse now I copied + pasted the code into a new Web Applet project. I found some problems I didn't spot before and updated the code in the web applet.
I want to add some buttons to the GUI, but one problem is its an annoyance to find the part of the code where NetBeans put all the variable declarations, then find another part of the code where all the fields are initialised, then find the other part of the code where the layout needs to be defined, then find the other part of the code where all the action listeners are added, etc... Another problem is that the Swing layouts are complex and also an annoyance to hard code... it is difficult to judge what the exact outcome will look like when you have to edit GroupLayouts with other swing components already layed out in them.
Also, I can't edit this in NetBeans because the Generator is very fussy and if I copy+paste code in there it wont read it as a Java Form nor generate an XML file which I think it uses to manage your layout.
Are there any free GUI designers out there that take a bunch of java swing code and allow you to graphically edit it? How do professionals manage their graphical layouts?
So I should have implemented the Model-View approach from the start.
Here is a nice tutorial on the subject:
http://people.csail.mit.edu/phw/OnToJava/ONTOJAVA755.HTML

How does Eclipse know whether the Swing Designer is available for a JFrame-derived class?

I am using Google Web Toolkit's Swing Designer in Eclipse to create and edit components like custom JFrame's.
The problem is that the Design View is sometimes broken for my class (probably because the project is also being edited by another person in a different platform), and I want to know how to restore it. In other words, I am able to edit the code for a custom JFrame, but I cannot use the visual editor to modify the JFrame anymore. I notice that the icon for my JFrame's source code also changes to a normal java-source-code icon when the design view is broken.
In which file does Eclipse keep track of what JFrame's can be edited using the visual editor and which ones not?
Thanks in advance.
If you want to open a file in the designer, but that's not happening by default, then use right-click Open With>WindowBuilder Editor.
If you don't see the Design tab, that means that you are just using the standard Eclipse Java Editor rather than the WindowBuilder editor. Eclipse allows you to use different editors via the Open With command. This is very basic Eclipse behavior, so it is something you should learn about. This is also covered in the WB docs and FAQ.

Is there a way to find out the class of form using eclipse?

I am working on a large undocumented application written in swing/awt. I have to make changes to it and i need to find out what class a form belongs to when i open it. Is there a way to do this via eclipse?
For example: I open the application and to do something with the app such that some frame opens. How do i find out the class of that form? Can this be done through eclipse?
I know i can comb trough the logic but this is a very laborious and largely ineffective process, chunks of the logic are either in jar files or obfuscated.
Thanks.
For figuring out how a given Swing frame is put together, I have found Swing Explorer to be VERY helpful.
https://swingexplorer.dev.java.net/
After installing the Eclipse plugin, note that you need to "Run as ->" to invoke Swing Explorer properly.
I don't know if this is what you need, but maybe you should try searching(MainMenu-->Search) your entire Project for the specific Window title (String) that comes up with this particular window.

Categories