I am developing an application in which I have some links added to the Listview
, and these links will keep on adding at runtime on some condition. What I can't find is a way to to open a url when clicking on a particular link.
This is the code for adding links into list view
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);
}
I know I need to use something like this to open a url in browser when click on link:
getHostServices().showDocument(link.getText());
I don't know how to listen/track the click event for different links.