Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/09/2014, 09:11
marcusaurelio
 
Fecha de Ingreso: enero-2007
Mensajes: 285
Antigüedad: 17 años, 3 meses
Puntos: 21
libreria pdf-renderer dentro de un jpanel

Hola como estan.. estoy tratando de hacer una vista previa de un pdf.. dentro de un jsplitpane... dentro del mismo ..quiero meter un visor de pdf que es pdf-renderer.jar.

https://java.net/projects/pdf-renderer

segun el ejemplo de la pagina... al hacer esto anda.. y es verdad..

Código:
public class NewClass {

    public void setup() throws IOException {
    
        //set up the frame and panel
        JFrame frame = new JFrame("PDF Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        PagePanel panel = new PagePanel();
        frame.add(panel);
        frame.pack();
      
        frame.setVisible(true);

        //load a pdf from a byte buffer
        File file = new File("C:/1.pdf");
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel channel = raf.getChannel();
        ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
        PDFFile pdffile = new PDFFile(buf);

        // show the first page
        PDFPage page = pdffile.getPage(0);
        panel.showPage(page);
        
     
        
    }

    public static void main(final String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    NewClass nc=new NewClass();
                            nc.setup();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        });
    }
}
pero cuando quiero poner el pagepanel en el jsplit pane.. deja de andar.. me dice.. NO PAGE SELECTED. por lo visto.. el truco esta donde hacer el pack.. pero no lo pude resolver.

si alguno tiene idea de como solucionarlo se lo agradeceria.