• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Launch default web browser from swing

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic