Question

I spent a long time creating a nice Dialog using Netbeans (Matisse), and now I realise that I want it as JPanel instead.

Is there any way of converting the Dialog to Panel in Netbeans. The blasted GUI editor does not allow me to modify any of the code.

Was it helpful?

Solution

Just open navigator in design mode in jdialog, copy components and paste in jpanel view. Like in below image.

enter image description here

As always @MadProgrammer recommends, if you don't add directly to the jdialog and instead of a custom container (like a jpanel), then it's easy to put in another components :D

OTHER TIPS

You can play a trick on Netbeans to convert it, with all your code:

Assuming your dialog class is called MyDialog:

  1. In Netbeans UI Editor, create a new empty JPanel form (say, e.g. MyDialogPanel), and save it.
  2. Quit Netbeans, and open your favorite file browser, navigate to the folder where your classes reside. You will find MyDialog.java and MyDialog.from - as well as MyDialogPanel.java and .form.
  3. Now open MyDialog.java, and replace JDialog by JPanel in the class definition, and save as MyDialogPanel.java (overwriting the empty panel you have created).
  4. Now open MyDialog.form, replace JDialogFormInfo by JPanelFormInfo, and save as MyDialogPanel.form (overwriting the empty panel you have created).
  5. Open Netbeans, and open MyDialogPanel. The UI editor will be suprised and probably hickup a warning. Choose to allow editing, and save the dialog. Now look through your code, you probably need to fix a few things (like usages of getContentPane() or dispose() or the like, which are not there in a JPanel. After that, voila! Everything there, in your JPanel!

Ah. Figured it out. Just need to create a JPanel Netbeans class. Then I can just copy and paste the components across from the JDialog by going into the navigator view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top