Ejemplo n.º 1
0
  private void createScreenShotButton() {
    screenShotButton = new Button(FontAwesome.ICON_CAMERA);
    screenShotButton.setFont(Font.font("FontAwesome", 14));
    screenShotButton.setTooltip(new Tooltip("Take Screen Shot."));
    //        screenShotButton.disableProperty().bind(webEngine.getLoadWorker().runningProperty());
    screenShotButton.setOnAction(
        observable -> {
          WritableImage image = masterPane.snapshot(null, null);
          SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss'.png'");

          FileChooser fileChooser = new FileChooser();
          fileChooser.setTitle("Save Screen Shot...");
          fileChooser.setInitialFileName(simpleDateFormat.format(Date.from(Instant.now())));
          File imageFile = fileChooser.showSaveDialog(null);

          if (imageFile != null) {
            try {
              ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", imageFile);
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        });
  }