【问题标题】:I need to print anchorPane in scenebuilder javafx我需要在scenebuilder javafx中打印anchorPane
【发布时间】:2018-08-07 15:45:19
【问题描述】:

我正在创建自定义的 TableView,然后我需要按照它们看起来的样子打印它们,所以我想为 AnchorPane 本身截取一个屏幕截图然后打印它,那么这是否可能?或者我应该怎么做?

【问题讨论】:

    标签: javafx-8 scenebuilder


    【解决方案1】:

    您可以将需要打印的所有结构放置在一个节点中,例如 anchorpane,然后将 anchorPane 传递给此代码,

    FileChooser exportFileChooser = new FileChooser(); //The folder selector to save the pdf   
    exportFileChooser.setInitialDirectory(FileSystemView.getFileSystemView().getDefaultDirectory());
    exportFileChooser.setInitialFileName(fileName);
    File file = new File("temp/"+fileName+".png");
    exportFileChooser.showSaveDialog(owner);
    file.getParentFile().mkdirs();//crete temp directory if not available
    final SnapshotParameters spa = new SnapshotParameters();
    spa.setTransform(javafx.scene.transform.Transform.scale(0.71, 1.1));//Scaling only if required i.e., the screenshot is unable to fit in the page
    WritableImage image = node.snapshot(spa, null);//This part takes the snapshot, here node is the anchorpane you sent
    BufferedImage buffImage = SwingFXUtils.fromFXImage(image, null);
    try {
     ImageIO.write(buffImage, "png", file);//Writes the snapshot to file
    } catch (Exception e) {
       e.printStackTrace();
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-26
      • 2017-06-15
      • 1970-01-01
      • 2015-07-03
      • 2015-07-22
      • 2014-09-17
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      相关资源
      最近更新 更多