Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open the default system browser from a java fx application?

I'm trying to open a web url in the default system browser from javafx. I didn't find any official documentation regard this. Any clue?

EDIT: I've found a tutorial but it doesn't work. I'm using MacOsX and I tried launching

java.awt.Desktop.getDesktop().browse(new URI(url)); 

but I get an HeadlessExcelption

like image 358
Advanced Avatar asked May 17 '13 08:05

Advanced


People also ask

Can JavaFX run in a browser?

The recommended way to embed a JavaFX application into a web page or launch it from inside a web browser is to use the Deployment Toolkit library. The Deployment Toolkit provides a JavaScript API to simplify web deployment of JavaFX applications and improve the end user experience with getting the application to start.


2 Answers

Use hostServices.showDocument(location).

Try placing the following code in your application's start method:

getHostServices().showDocument("http://www.yahoo.com"); 
like image 168
jewelsea Avatar answered Oct 01 '22 23:10

jewelsea


Complementing jewelsea's answer, if you don't know how to call getHostServices() then try this at your main class:

HostServicesDelegate hostServices = HostServicesFactory.getInstance(this); hostServices.showDocument(WEBSITE); 

http://docs.oracle.com/javafx/2/api/javafx/application/HostServices.html#showDocument(java.lang.String)

like image 38
ceklock Avatar answered Oct 02 '22 01:10

ceklock