0

I am currently stuck in using Hyperlink type to browse a website in Javafx.

I am required to create a Hyperlink type with a designated name. When I click the link, a website should be popped up.

My code is:

@FXML
private Hyperlink labelMin;

...

public class Item{
...
    public void getPrice();
    public void getUrl(); //I can get the url in string form using this function.
}

...

if (item.getPrice() < min){
    labelMin.setText(String.valueOf(item.getPrice()));
}

The above code correctly displays a hyperlink with text item.getPrice(). It is clickable but nothing happens. What can I do in order to browse a website?

DAA
  • 1,346
  • 2
  • 11
  • 19
HangBB
  • 1
  • 1

1 Answers1

0

Try this code

labelMin.setOnAction((event) -> {
    try {
    new ProcessBuilder("browser", "https://google.com").start();
    } catch (IOException e) {
    e.printStackTrace();
    }
});

Url of the website which you want to try should be placed where google's address has been placed.

Azhar
  • 74
  • 8
  • possible but ... why not use the built-in support ;) see the referenced qa in the comment to the question – kleopatra Oct 09 '18 at 10:18