estou com um problema na impressão de relatório e não sei mais o que fazer gostaria da ajuda de vcs.
Código:
package br.com.infox.telas;
import br.com.infox.dal.ModuloConexao;
import java.text.DateFormat;
import java.util.Date;
import javax.swing.JOptionPane;
import java.sql.*;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
public class TelaPrincipal extends javax.swing.JFrame {
Connection conexao = null;
/**
* Creates new form TelaPrincipal
*/
public TelaPrincipal() {
getContentPane().setBackground(Color.WHITE);
initComponents();
conexao = ModuloConexao.conector();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
lblUsuario = new javax.swing.JLabel();
lblUsuario.setBackground(Color.WHITE);
lblUsuario.setForeground(SystemColor.textHighlight);
lblData = new javax.swing.JLabel();
lblData.setBackground(Color.WHITE);
lblData.setForeground(SystemColor.textHighlight);
jLabel3 = new javax.swing.JLabel();
desktop = new javax.swing.JDesktopPane();
menuPrincipal = new javax.swing.JMenuBar();
menCad = new javax.swing.JMenu();
menCadCli = new javax.swing.JMenuItem();
menCadOS = new javax.swing.JMenuItem();
menCadUsu = new javax.swing.JMenuItem();
menRel = new javax.swing.JMenu();
menRelCli = new javax.swing.JMenuItem();
menRelSer = new javax.swing.JMenuItem();
menAju = new javax.swing.JMenu();
menAjuSob = new javax.swing.JMenuItem();
menOpc = new javax.swing.JMenu();
menOpcSai = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Sistema para controle de OS");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
lblUsuario.setFont(new Font("Arial", Font.BOLD, 18)); // NOI18N
lblUsuario.setText("Usuário");
lblData.setFont(new Font("Arial", Font.BOLD, 18)); // NOI18N
lblData.setText("Data");
jLabel3.setIcon(new ImageIcon(TelaPrincipal.class.getResource("/br/com/infox/icones/x.png"))); // NOI18N
desktop.setPreferredSize(new java.awt.Dimension(640, 480));
javax.swing.GroupLayout desktopLayout = new javax.swing.GroupLayout(desktop);
desktop.setLayout(desktopLayout);
desktopLayout.setHorizontalGroup(
desktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 640, Short.MAX_VALUE)
);
desktopLayout.setVerticalGroup(
desktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
menCad.setText("Cadastro");
menCadCli.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
menCadCli.setText("Cliente");
menCadCli.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menCadCliActionPerformed(evt);
}
});
menCad.add(menCadCli);
menCadOS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK));
menCadOS.setText("OS");
menCadOS.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menCadOSActionPerformed(evt);
}
});
menCad.add(menCadOS);
menCadUsu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.ALT_MASK));
menCadUsu.setText("Usuários");
menCadUsu.setEnabled(false);
menCadUsu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menCadUsuActionPerformed(evt);
}
});
menCad.add(menCadUsu);
menuPrincipal.add(menCad);
menRel.setText("Relatório");
menRel.setEnabled(false);
menRelCli.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK));
menRelCli.setText("Clientes");
menRelCli.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menRelCliActionPerformed(evt);
}
});
menRel.add(menRelCli);
menRelSer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
menRelSer.setText("Serviços");
menRelSer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menRelSerActionPerformed(evt);
}
});
menRel.add(menRelSer);
menuPrincipal.add(menRel);
menAju.setText("Ajuda");
menAjuSob.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
menAjuSob.setText("Sobre");
menAjuSob.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menAjuSobActionPerformed(evt);
}
});
menAju.add(menAjuSob);
menuPrincipal.add(menAju);
menOpc.setText("Opções");
menOpcSai.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
menOpcSai.setText("Sair");
menOpcSai.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menOpcSaiActionPerformed(evt);
}
});
menOpc.add(menOpcSai);
menuPrincipal.add(menOpc);
setJMenuBar(menuPrincipal);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(desktop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3))
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblData)
.addComponent(lblUsuario))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(59, 59, 59)
.addComponent(lblUsuario)
.addGap(37, 37, 37)
.addComponent(lblData)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(desktop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void menCadOSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menCadOSActionPerformed
// TODO add your handling code here:
// chamando a TelaCliente
TelaOS os = new TelaOS();
os.setVisible(true);
desktop.add(os);
}//GEN-LAST:event_menCadOSActionPerformed
private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
// ao ativar a janela, mude e atualize a data:
Date data = new Date();
// atenção ao .toString
//lblData.setText(data.toString());
// formatando a data
DateFormat formatador = DateFormat.getDateInstance(DateFormat.SHORT);
lblData.setText(formatador.format(data));
}//GEN-LAST:event_formWindowActivated
//
private void menOpcSaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menOpcSaiActionPerformed
int sair = JOptionPane.showConfirmDialog(null, “Tem certeza que deseja sair?”, “Atenção”, JOptionPane.YES_NO_OPTION);
if (sair == JOptionPane.YES_OPTION) {
System.exit(0);
}
}//GEN-LAST:event_menOpcSaiActionPerformed
private void menCadUsuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menCadUsuActionPerformed
// as linhas abaixo abrir o form TelaUsuario dentro do desktop pane
TelaUsuario usuario = new TelaUsuario();
usuario.setVisible(true);
desktop.add(usuario);
}//GEN-LAST:event_menCadUsuActionPerformed
private void menAjuSobActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menAjuSobActionPerformed
TelaSobre sobre = new TelaSobre();
sobre.setVisible(true);
}//GEN-LAST:event_menAjuSobActionPerformed
private void menCadCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menCadCliActionPerformed
// chamando a TelaCliente
TelaCliente cliente = new TelaCliente();
cliente.setVisible(true);
desktop.add(cliente);
}//GEN-LAST:event_menCadCliActionPerformed
private void menRelCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menRelCliActionPerformed
// gerando um relatório de clientes
int confirma = JOptionPane.showConfirmDialog(null,"Confirma a impressão deste relatório?","Atenção",JOptionPane.YES_NO_OPTION);
if (confirma == JOptionPane.YES_OPTION){
//imprimindo relatório com o framework JasperReports
try {
//Usando a classe JasperPrint para preparar a impressão de um relatório
JasperPrint print = JasperFillManager.fillReport("C:/reports/clientes.jasper",null,conexao);
//a linha abaixo exibe o relatório através da classe JasperViewer
JasperViewer.viewReport(print,false);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}//GEN-LAST:event_menRelCliActionPerformed
private void menRelSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menRelSerActionPerformed
// gerando um relatório de serviços
int confirma = JOptionPane.showConfirmDialog(null,"Confirma a emissão deste relatório?","Atenção",JOptionPane.YES_NO_OPTION);
if (confirma == JOptionPane.YES_OPTION){
//emitindo o relatório com o framework JasperReports
try {
//Usando a classe JasperPrint para preparar a impressão de um relatório
JasperPrint print = JasperFillManager.fillReport("C:/reports/servicos.jasper",null,conexao);
//a linha abaixo exibe o relatório através da classe JasperViewer
JasperViewer.viewReport(print,false);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}//GEN-LAST:event_menRelSerActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TelaPrincipal().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JDesktopPane desktop;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel lblData;
public static javax.swing.JLabel lblUsuario;
private javax.swing.JMenu menAju;
private javax.swing.JMenuItem menAjuSob;
private javax.swing.JMenu menCad;
private javax.swing.JMenuItem menCadCli;
private javax.swing.JMenuItem menCadOS;
public static javax.swing.JMenuItem menCadUsu;
private javax.swing.JMenu menOpc;
private javax.swing.JMenuItem menOpcSai;
public static javax.swing.JMenu menRel;
private javax.swing.JMenuItem menRelCli;
private javax.swing.JMenuItem menRelSer;
private javax.swing.JMenuBar menuPrincipal;
// End of variables declaration//GEN-END:variables
}
Erro
20/07/21 20:52:41 INFO xml.XmlBeanFactory: Overriding bean definition for bean ‘titleURLText’: replacing [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
20/07/21 20:52:41 INFO xml.XmlBeanFactory: Overriding bean definition for bean ‘titleExpandToFitSpace’: replacing [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
20/07/21 20:52:41 INFO xml.XmlBeanFactory: Overriding bean definition for bean ‘subtitleVisible’: replacing [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
20/07/21 20:52:41 INFO xml.XmlBeanFactory: Overriding bean definition for bean ‘subtitlePosition’: replacing [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
20/07/21 20:52:41 INFO xml.XmlBeanFactory: Overriding bean definition for bean ‘subtitleFont’: replacing [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
20/07/21 20:52:41 INFO xml.XmlBeanFactory: Overriding bean definition for bean ‘subtitleForecolor’: replacing [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
20/07/21 20:52:41 INFO xml.XmlBeanFactory: Overriding bean definition for bean ‘subtitleBackcolor’: replacing [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.beans.factory.config.FieldRetrievingFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
