• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a new window or call an exisiting

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will the code below just create a new blank window rather than call the one I have? I want to call the one I have from my main method ideally.

 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will create a new window. Don't create new windows. Actually windows are pretty useless because they don't have minimise maximise and exit buttons. Use frames instead.

So don't write listeners which create new windows like that. You obviously want something to become visible there. Why do you want to access your window from the main method? I would have thought you create a delete window object in the constructor/initGUI method and you can set it invisible. When you click that menu item, it becomes visible and comes to the front.
Alternative option: Create a dialogue window, which goes out of scope and disappears when it is finished with.
Another alternative: Have the window visible as an [urlhttp://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html]internal frame[/url]. Bring it to the front when you click the menu item.
Yet another option: Have the window visible but push it to the back with the layout. I have never tried it myself, but I believe card layout can do that.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have tabbed panes, too.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell thanks for answering my question. I have a main class that uses the main window and that has a menu, in the menu there is a 'delete' option - when that is clicked on I just want to show my 'deleteWindow' which is in my other class.

What it is being used for - I don't need a minimise/maximise option, I just need to make it close if the cancel button is clicked

Do you have any examples of your first method you mentionned?

I have that for my other one the difference is the items in the parameters whether as for my delete I don't believe I have anything I need to put in:

 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have any examples at the moment, I am afraid.
What you have shown with the window becoming visible is equivalent to using a dialogue.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell,

I am using a JDialog for my 'deleteWindow' - will that make things easier for me?
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would have made things much easier to understand had you called it deleteDialogue. That is the correct way to create a dialogue; I presume it goes out of scope and is eligible for garbage collection at the end of that method. Go through the Java Tutorials link I provided earlier. You can have a dialogue hidden from sight and have it appear if you prefer. Go through the link in the same Java Tutorials “trail” about file choosers, because file choosers behave rather like dialogues.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!