how open image with url in javafx

≡放荡痞女 提交于 2020-06-17 03:28:31

问题


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:


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));


来源:https://stackoverflow.com/questions/26973860/how-open-image-with-url-in-javafx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!