有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

有人能帮我解决在JavaSwing中显示PDF的代码中的错误吗?

这段代码是为了在swing中查看PDF,但当我打开任何PDF时,内容都不可见,出现空白页面。我使用的是icepdf核心和查看器jar文件

public class PDFView{

    public static void main(String[]args) {

        SwingController controller = new SwingController();
        SwingViewBuilder factory = new SwingViewBuilder(controller);
        controller.setIsEmbeddedComponent(true);

        DocumentViewController viewController = controller.getDocumentViewController();

        JPanel viewerComponentPanel = factory.buildViewerPanel();
        ComponentKeyBinding.install(controller, viewerComponentPanel);

        controller.getDocumentViewController().setAnnotationCallback(
                new org.icepdf.ri.common.MyAnnotationCallback(
                        controller.getDocumentViewController()));

        JFrame applicationFrame = new JFrame();
        applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        applicationFrame.getContentPane().setLayout(new BorderLayout());
        applicationFrame.getContentPane().add(viewerComponentPanel,BorderLayout.CENTER);
        applicationFrame.getContentPane().add(factory.buildCompleteMenuBar(),BorderLayout.NORTH);

        controller.setPageViewMode(DocumentViewControllerImpl.ONE_PAGE_VIEW, false);

        applicationFrame.pack();
        applicationFrame.setVisible(true);
    }}

在这里找到截图

代码中的错误和警告

[enter image description here]

PDF的输出视图

enter image description here


共 (0) 个答案