File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Swing Multiple Window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing Multiple Window" Watch "Swing Multiple Window" New topic
Author

Swing Multiple Window

Mark Hagan
Greenhorn

Joined: Dec 08, 2011
Posts: 3
Hello,

What is the best way to code a swing application that has two windows where the first window has a button that creates the second window?

I've attached the code. You'll notice I'm creating the second window from the button handler on lines 42 and 53-48. Maybe this is the wrong way to generate a second window from a button?

On line 92, I'm trying to dispose the second window upon clicking the "Close" button. However, nothing happens when the "Close" button is clicked. I've also tried the setVisible(false) method, but get the same results.

Thanks for any help.

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

here is an example i wrote long ago that might help you;
one frame generating another
for your other question, have you tried:
setDefaultCloseOperation(EXIT_ON_CLOSE);


SCJP
Visit my download page
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Hi Mark,
Welcome to Javaranch!

For multiple windows you can check out using JDialog or may be using JInternalFrame within a JDesktopPane. This has been asked a few times before, so you might end up with few answers if you search in this forum.

And I have moved the post to an appropriate forum


Mohamed Sanaulla | My Blog
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
Why would you write a 300 line program to test something?

If you want to test opening a window when clicking a button, then create a JFrame with a JButton that opens another JDialog. That should be about 20-30 lines of code. Then once you understand the basics you can apply the solution to your real program.

This program is called an SSCCE.
Mark Hagan
Greenhorn

Joined: Dec 08, 2011
Posts: 3
Rob Camick wrote:Why would you write a 300 line program to test something?


I did not write this program to solely test my problem. All other functionality of the program works except for this small piece. This is a final program that I wrote for an on-line course. I've been back and forth with the Instructor on the problem, but I'm not seeing her points. Thus, the reason I posted here. I hoped for a different perspective that might "dim up" the bulb in my thick head. I apologize for pasting a 300 line program here (I had a sense it would raise eyebrows on an internet forum), but I thought it might help provide context.

I have looked into opening a JDialog with the button, but I'm not seeing how to do it yet. Does anyone have any examples of how to do that?

Thanks again for the help.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

You can start here
Mark Hagan
Greenhorn

Joined: Dec 08, 2011
Posts: 3
Got it to work using JDialog for the second window after finding an example on this site. Thanks all for the help.
 
 
subject: Swing Multiple Window