如何从java fx应用程序中打开默认系统浏览器? [英] How can I open the default system browser from a java fx application?

查看:704
本文介绍了如何从java fx应用程序中打开默认系统浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在javafx的默认系统浏览器中打开一个网址。我没有找到任何关于此的官方文件。任何线索?

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?

编辑:
我发现一个教程,但它不起作用。
我正在使用MacOsX,我尝试启动

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));

但我得到 HeadlessExcelption

推荐答案

使用 hostServices.showDocument(location)

尝试将以下代码放入你的应用程序的启动方法:

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

getHostServices().showDocument("http://www.yahoo.com");

这篇关于如何从java fx应用程序中打开默认系统浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆