1

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

Hayk Harutyunyan
  • 117
  • 1
  • 3
  • 17

1 Answers1

14

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));
Community
  • 1
  • 1
eckig
  • 10,964
  • 4
  • 38
  • 52