This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Open browser/web page from a swing app  RSS feed

 
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
 
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 ]
 
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
 
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 ]
 
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!
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
free 1 hour java lesson
https://coderanch.com/t/695988/free-hour-java-lesson
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!