AnsweredAssumed Answered

How to add Jpanel components to a Plex panel

Question asked by Gavin on Oct 7, 2014
Latest reply on Nov 8, 2014 by George Jeffcock

The code below opens a PDF document in a Jpanel. I have managed to create it as a source code object and calling it opens up a new Jpanel window.

 

Is there a way to add this to a plex panel so that I can add additional functionality using plex, for example data fields.

 

I would assume I would need to modify the code around the JFrame() part to reference a Plex Panel or Control on a plex panel?

 

 

import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.util.PropertiesManager;

import javax.swing.*;
import java.util.ResourceBundle;

{
        // Get a file from the command line to open
        String filePath = "C:/PDFLocal/Gen/Bld/CA Plex 71.pdf";

        // build a component controller
        SwingController controller = new SwingController();
        controller.setIsEmbeddedComponent(true);

        PropertiesManager properties = new PropertiesManager(
                System.getProperties(),
                ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));

        properties.set(PropertiesManager.PROPERTY_DEFAULT_ZOOM_LEVEL, "1.75");

        SwingViewBuilder factory = new SwingViewBuilder(controller, properties);

        // add interactive mouse link annotation support via callback
        controller.getDocumentViewController().setAnnotationCallback(
                new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

        JPanel viewerComponentPanel = factory.buildViewerPanel();
        JFrame applicationFrame = new JFrame();
      

        applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        applicationFrame.getContentPane().add(viewerComponentPanel);
        // Now that the GUI is all in place, we can try openning a PDF
        controller.openDocument(filePath);
        // show the component
        applicationFrame.pack();
        applicationFrame.setVisible(true);
    }

Outcomes