Issue
I am new to NetBeans IDE and I am using NetBeans GUI builder for creating my GUIs. I am creating a new file by right-clicking the package and click new and then click the new JFrame Form.
It is working fine. But I have a java file with a JFrame which I created manually by coding.
Can I import it into that GUI builder so that I can drag and drop and make the GUI? If yes How can I do that? (In eclipse we can do that by right-clicking the file and click open with windowbuilder editor.)
Solution
The Netbeans GUI builder works by generating code fully controlled by Netbeans, plus it maintains a hidden .form
file. So you can't directly import your JFrame
and make it fully customizable by the GUI Builder.
However there are things that might help.
You can modify your JFrame
by adding JPanels
designed using the GUI Builder. In Netbeans project view, select your package and create a new JPanel form, edit it, save it. Then in your JFrame
code, manually insert JPanel
instances where you need it.
Another trick:
- Extract the UI code from your
JFrame
and create aJPanel
file with it, with a public no-argument constructor. - Compile it
- Select the JPanel file in the Netbeans projet view, then righ-click Tools/Add to palette
- Add it to a Category (you can create your own category if needed)
- Create a new JFrame form from Netbeans
- You should see your
JPanel
component available in the GUI builder palette, in the relevant Category - Drag & drop your
JPanel
component in theJFrame
form
Note that the JPanel will not be editable itself, you can just manipulate it as a block in the GUI builder.
NOTE: in my experience, after doing Tools/Add to palette, it's sometimes needed to close/reload a form file to have the added component actually appear in the GUI builder palette.
Answered By - jjazzboss
Answer Checked By - Marie Seifert (JavaFixing Admin)