Usually in a Swing application if I want to display JDialogs to the user, I create them once and then reuse them.
Usually the main JFrame has references to these JDialogs.
Sometimes though I need to display a JDialog from parts of code outside the JFrame class.
Usually I make the JDialog member variables (of JFrame) public and either they are static or pass a reference of the JFrame arround to be able to access the JDialog.
It works but it seems messy to me.
I was wondering is there a standard design approach for something like this?
Usually in a Swing application if I want to display JDialogs to the user,
Share
My own philosophy is to make almost all fields private, including the dialog and only expose that which needs exposing, no more and no less. For instance if I have a JDialog called from another class and I get information from that dialog, I expose only the information via public getter methods, not the dialog itself.
Edit 1
Sorry for some gross over-kill and much longer than expected code, but this is kind of what I meant in an MVC sort of way and created in a great hurry:
The key here is that the MainPanel has no knowledge about the DialogPanel and visa-versa since it’s all connected by the MainControl through the marvels of MVC.