Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open browser/web page from a swing app

 
Robert Upshall
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool class.
well done!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic