0

Say I have the following code:

public class MainDialog extends javax.swing.JFrame 
{
    static class SubDialog extends javax.swing.JDialog
    {

    }
}

If I open 'MainDialog.java' in design mode, I can only edit the GUI of the MainDialog class. Is there anyway to edit the SubDialog class in design mode?

Thanks

  • Not as far as I'm aware... – MadProgrammer May 27 '14 at 01:08
  • Are you sure? That is very inconvenient. How do developers work around this if they need access to private members in the outer class? – Jeremy Collette May 27 '14 at 01:13
  • To even be "close" to been acceptable, the inner dialog would need to be `public` and `static` as Netbeans needs a way to create an instance of the dialog – MadProgrammer May 27 '14 at 01:13
  • 1
    They don't. They create separate, single based class based forms which are then configurable in some way, passing references of what they need backwards and forwards between them. Personally, I tend to hand code most my UIs and only rely on the form editor when time a is pressure or the layout is especially complex – MadProgrammer May 27 '14 at 01:15
  • Amen to that posted by @MadProgrammer programmer above. Your original plan does not lead to much re-usable or enhanceable code. – Hovercraft Full Of Eels May 27 '14 at 01:17
  • How did you even get that JDialog class defined like that in the frame class? – Paul Samsotha May 27 '14 at 01:47
  • I typed it myself. The idea was to create a "Settings" dialog that could change private variables in the outer-class. However, given the feedback from @MadProgrammer, I guess the way I should do this is by passing the different 'settings' (or possibly the outer-class itself) to the stand-alone form and retrieving new values once the dialog is closed. – Jeremy Collette May 27 '14 at 01:54
  • MadProgrammer is correct, separate classes are the way to go. But just so you know, Whatever code you type, don't expect it to be editable by the editor. Bu you _could_ drag and drop a dialog to the frame. Then go to the navigator window and you will see the dialog. You can double click it and it will show in the design view. Make sure you hand code to `pack() and `setVisible()` to it when you want to show it. But like I said, MadProgrammer gave you the more appropriate solution – Paul Samsotha May 27 '14 at 01:59
  • Thanks for the tip @peeskillet. I tried that too but I still couldn't make it an inner-class dialog. – Jeremy Collette May 27 '14 at 02:04
  • @MadProgrammer if you want to re-iterate what you said as an answer I will select it. – Jeremy Collette May 27 '14 at 02:04

1 Answers1

2

To even be "close" to been acceptable, the inner dialog would need to be public and static as Netbeans needs a way to create an instance of the dialog.

Most developers will create separate, single based class, based forms which are then configurable in some way (via setters and getters), passing references of what they need backwards and forwards between them.

Personally, I tend to hand code most my UIs and only rely on the form editor when time a is pressure or the layout is especially complex

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366