Initialize GUI components in IntelliJ - java

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.

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.

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

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.

Creation of array of gui components using netbeans gui builder

I have been finding it difficult to create an array in netbeans because I am using the gui builder. Netbeans does not allow me to add any code to the guarded code region. I have searched online for a solution but to no avail. I created the array after initcomponent but it is throwing an illegal forward reference error because the array is defined before the gui components. My issue now is i want to make the array a class variable, i don't want to declare it as a local variable to a method. What can I do?
I don't know about your problem (sounds like your coding structure problem to me). But I will still tell you how to edit netbeans code.
First go into your project folder (Default is: C:/users/username/Documents/Netbeans Projects/ProjectName
Then go inside the src folder. And there you have your source code. All .java files are your source code (there are also .form files, but dont mess with them. Thats netbeans GUI builder data you dont want messing with).
Open the java source code with any text editor, edit and save your code, open netbeans and refresh it (right click project name and refresh). You have changed the unchangeable code.
You can add an array field after the variable declaration region. Place the caret at the closing } of the class and you can create lines below the generated region.

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

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