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.So what I can't find is a way to how 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());
but I don't know how to listen/track the click event for different links
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…