我正在开发一个应用程序,其中我有一些链接添加到Listview,这些链接将继续在运行时添加某些条件.所以我找不到的是如何在单击特定链接时打开URL的方法.
这是将链接添加到列表视图的代码
if(counter==1)
{
Task task2 = new Task<Void>() {
@Override
public Void call() throws Exception {
Platform.runLater(new Runnable() {
public void run() {
link=new Hyperlink(val);
link.setStyle("-fx-border-style: none;");
items.add(link);
listview.setItems(items);
}
});
return null;
}
};
Thread th = new Thread(task2);
th.setDaemon(true);
th.start();
Thread.sleep(1000);
}
Run Code Online (Sandbox Code Playgroud)
我知道我需要使用这样的东西在浏览器中点击链接时打开一个网址
getHostServices().showDocument(link.getText());
Run Code Online (Sandbox Code Playgroud)
但我不知道如何监听/跟踪不同链接的点击事件