aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Open browser/web page from a swing app 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 browser/web page from a swing app" Watch "Open browser/web page from a swing app" New topic
Author

Open browser/web page from a swing app

Robert Upshall
Greenhorn

Joined: Aug 23, 2001
Posts: 25
I have a Swing application, the application has a menu bar with a Help menu, the Help menu has an "Our Website" menu item.
I want to know what I need to do to make an event open a browser/web page. I know how to trap the action, I need to know what I need to do to open a browser.
Robert
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879


where temp.html is a link to your web page ( or have it automatically redirect people to your site ).
p.s. for the redirect source code, just view the page source at javaranch after you submit a post ("Sit tight... We are taking you back to: ...")
Jamie
[ April 26, 2002: Message edited by: Jamie Robertson ]
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
i once wanted to do the same thing. here is what i did although i am 100% sure there is a better way.

notice that the file://help.html can be replaced with any html documnet you got on your mcahine or input a URL using http:// instead.
also notice this will work ONLY in windows.
Robert Upshall
Greenhorn

Joined: Aug 23, 2001
Posts: 25
Thanks, this worked.
I have another question now, are there any platform independant ways? ie. how might I do this in linux or Mac OS?
Robert
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
i dont think there are any platform independant ways. cause the browser opens diffrently on every OS.
again i may be wrong
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

And you also can't be sure of what browsers are installed or what directories they are installed in.... the only platform independent way to do this would be to have the user set up what browser they wanted to use with your program so you would know what command to run...

You could also use a JEditorPane... but since this just has basic HTML support, you'd end up coding your own browser if you wanted anything fancy like javascript...

-Nate
[ April 29, 2002: Message edited by: Nathan Pruett ]

-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
I wrote a class that will let you launch a url in a Browser on many platforms from your Java application:
http://ostermiller.org/utils/Browser.html
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
cool class.
well done!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Open browser/web page from a swing app