how open image with url in javafx


Question

I have banner an I wont to put it in my javaFX application. And when user click on the image open default browser.

try {
            String path = "http://developer.am/webservice/banner728x90.gif";
            URL url = new URL(path);
            BufferedImage image = ImageIO.read(url);
            label = new JLabel(new ImageIcon(image));

        } catch (Exception exp) {
            exp.printStackTrace();
        }

also I am trying to convert above code from awt in JavaFX

1
1
11/17/2014 1:32:33 PM

Lets see. First the ingredients:

  1. Image
  2. Button
  3. ImageView
  4. Open Link in System Browser with JavaFX

Putting this together:

String path = "http://...";
String pathToOpen = "http://...";

Image image = new Image(path);
ImageView imageView = new ImageView(image);

Button button = new Button("clickMe!", imageView);
button.setOnAction(ev -> getHostServices().showDocument(pathToOpen));
11
5/23/2017 12:17:30 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon