Ver Mensaje Individual
  #4 (permalink)  
Antiguo 02/09/2010, 09:36
ioel10
 
Fecha de Ingreso: julio-2010
Mensajes: 104
Antigüedad: 14 años, 8 meses
Puntos: 2
Respuesta: Problema al imprimir desde java

Buenas tardes,

Pense que en el método imprimir() te crearías un jasperPrint, no un printJob, no puedo ayudarte ya que siempre imprimo mediante jasperReport. Tu Frame si no he leído y entendido mal sólo tiene un un label, un textfield y el botón imprimir, y lo que pretendes con la impresión es un hoja en la que en el centro figure el texto del textfield, con jasper esto es facilito.

Ireport:

1. Crea un report llamado "informe".

2. Crea un parameter o parametro llamado "texto".

3. Arrastrar el parametro a la seccion Detail, te debería aparecer un recuadro con "$P{texto}".

4. Compila el report.

Java:
Código java:
Ver original
  1. JasperPrint print = new JasperPrint();
  2.                 Map parameters = new HashMap();
  3.  
  4.                 File rutaCarpetaExpediente = new File(tuRutadelInforme);
  5.  
  6.                 if (!rutaCarpetaExpediente.exists()) {
  7.                     rutaCarpetaExpediente.mkdir();
  8.                 }
  9.  
  10.                 parameters.put("texto", cadena);
  11.  
  12.                 try {
  13.                            //Archivo de impresion
  14.                           print = JasperFillManager.fillReport(rutaCarpetaExpediente.getAbsolutePath() + File.separatorChar + "informe.jasper", parameters);
  15.                      } catch (JRException ex) {
  16.                               ex.printStackTrace();
  17.                      }
  18.  
  19.                 //Mostramos la pantalla de impresion
  20.                 JasperViewer view = new JasperViewer(print, false);
  21.  
  22.                 view.setVisible(true);

No lo he probado, pero si funciona no debería tardar nada...

Un saludo y buen día.