Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Launch default web browser from swing

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it possible to launch the default browser to display a URL from a Swing application? Not an applet. Can anyone shed some lights how to do it please? I can't find anything in Google that is not about Applets. I want to pop up a browser window for the user guide in the JMenuBar.

Thanks again!
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think codes for bringing up a default browser is system dependent and should be avoided. I might be wrong though.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what this has to do with SCJD (which this forum is about), but Eric Albert's BrowserLauncher class does a very good cross-platform job of starting a browser.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anna -

have a look at javax.swing.JTextPane - it's capable of displaying a simple html file, and can be embedded in a JScrollPane in a JPanel. Unless you're trying to do something really complicated, that would probably suffice.
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The BrowserLauncher class looks too complicated for so little use. I want to pop up the browser for the user guide in the menu bar. Using TextPane looks complicated too. Maybe I should take away this option...
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The BrowserLauncher class is indeed complicated, but using it is extremely simple:

BrowserLauncher.openURL("file://...";)

is all that's required. You can also pass in an HTTP URL.
 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Textpane really isn't that complicated. It can load a file from a url via JTextPane.setPage(java.net.URL url) and the system classloader can give you a URL back to your help file. As for setting it up in a panel, it's just the same as any other swing GUI component. My help system class weighed in at 120 lines including lots of comments.

That said, you have to be happy with your own solution - best of luck!
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BrowserLauncher seem to be a class that I want to rip off for work, it looks really handy.

Thanks for the help, I will look into TextPane more because I can't use the BrowserLauncher as part of my submission.
 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic