GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Open New Window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Open New Window" Watch "Open New Window" New topic
Author

Open New Window

Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,
I want to open a new window on the click of a button("finish").
At the same moment I want to close my parent window from where the swing application opened initially and now open the new one.

Please suggest me the way by which I can do the same.

Thanks
Kushagra
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10425
    
    8

oldFrame.setVisible(false) will hide your existing UI, whereas newFrame.setVisible(true) will show your new frame. Of course you have to build your new frame first. But since you already have built your old frame, that shouldn't be a problem.

Since you mentioned hiding the original frame, I presumed you do not want modal dialog windows.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,

I want to close the main window is the oldFrame.setVisible(false); will close it or make it invisible. Also I want to know that oldFrame and newFrame are objects of which class.

Actually my browse button is on Web page which will then open my swing application.
As my application will have to refresh the web application so I want to open the new web page instead of new one. Is it possible to do the same as you suggest.

Thanks
Kushagra
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10425
    
    8

oldFrame and newFrame would be instances of JFrame. Check the API to find out what exactly setVisible(false) means.

Actually my browse button is on Web page which will then open my swing application.
As my application will have to refresh the web application so I want to open the new web page instead of new one. Is it possible to do the same as you suggest.

Please tell the details.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,
Actually my requirement is to open a fresh new IE instance on the click of a button independently.

Thanks
Kushagra
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10425
    
    8

Which button? Is it a button on an HTML page which is being displayed in IE?
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
No this button is on swing window and on click on whcih I want to open a new webpage let say "www.google.com"

Thanks
Kushagra
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10425
    
    8

This question comes up many times.
Search this forum for opening URLs from Swing applications.

Please note that opening a URL and opening IE(like you mentioned in your previous post) are two different things.
While opening URLs the "preferred system browser" setting is considered and it might not be IE.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Ya you are right.

I want to open the prefered browser on click of the button and want to close previously open browser that initially open my swing application.

Thanks
Kushagra
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

That last part is going to be a problem, since your Swing application knows nothing about how it was started, and therefore does not know about the IE window. And closing just any IE window will not do; even if there is just one active window, there is no guarantee that that is the window that opened your app - the user could have closed it manually and opened another window. Or he could have used that window to open a different page.

Note that if your Swing application is in fact a JApplet, then you can do what you want. Use getAppletContext().showDocument(...) to do just that.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: Open New Window