ciao a tutti!!! sono riuscita a creare un file.jrxml con iReport e a creare da questo un file pdf ed excel, per visualizzarlo abbiamo pensato ad un bottone che faccia visualizzare nel jasper viewer il file pdf o excel:

1)Jframe, che contiene il bottone:
codice:
package Schedule.DB;

import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;


public class JFrame extends javax.swing.JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JButton jButton = null;

	public JFrame() {
		super();
		initialize();
	}

	private void initialize() {
		this.setSize(300, 200);
		this.setTitle("JFrame");
		this.setContentPane(getJContentPane());
	}

	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJButton(), null);
		}
		return jContentPane;
	}

	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(115, 78, 80, 44));
			jButton.addActionListener(new ActionListener() {
				@SuppressWarnings("static-access")
				public void actionPerformed(ActionEvent evt) {
					System.out.println("jButton.actionPerformed, event="+evt);
					SQLManager sqlm = new SQLManager("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/schedule","root","root");
					
					try{
						MainTest mt = new MainTest();
						mt.main(null);
						@SuppressWarnings("unused")
						JasperPrint print=JasperFillManager.fillReport("C://TEMP/Report.jasper", null);
						JasperViewer.viewReport(print,false);
						
					}catch(Exception e){
					sqlm.close(); 
					}
jButton.actionPerformed
				}
			});
		}
		return jButton;
	}

}
2)MainTest, che contiene il codice che genera i 2 file:
codice:
package Schedule.DB;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;

public class MainTest {

MainTest() {
}

@SuppressWarnings({ "unchecked", "unchecked" })
public static void main(String[] args) {
try{

//File jasper sorgente
String fileName="C://TEMP/Report.jasper";
//File pdf di destinazione
String destFileNamePdf="C://TEMP/Report.pdf";
//File xls di destinazione
String destFileNameXls="C://TEMP/Report.xls";

//Passaggio parametri da passare al jasper.
Map parameters = new HashMap();
parameters.put("param1", new Integer(1));

//Preparazione del file da stampare (in questa fase si esegue la query e si inseriscono
//i valori estratti dalla query)
JasperPrint jasperPrint=JasperFillManager.fillReport(fileName, parameters, getConnection());

//Creazione del PDF
JasperExportManager.exportReportToPdfFile(jasperPrint, destFileNamePdf);

//Creazione dell'xls
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileNameXls);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
exporter.exportReport();

System.exit(0);
}catch (Exception e){
e.printStackTrace();
}

}

private static Connection getConnection() throws ClassNotFoundException, SQLException {
String driver = "com.mysql.jdbc.Driver";
String connectString = "jdbc:mysql://localhost:3306/schedule";
String user = "root";
String password = "root";

Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}

}
alla fine di tutto ciò i file vengono creati, ma non riesco a visualizzarli, visto che secondo l'errore che da' il jasper viewer risulta vuoto ...

[errore]
jButton.actionPerformed, event=java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=,when=1215187299636,modifiers =Button1] on javax.swing.JButton[,115,78,80x44,alignmentX=0.0,alignmentY=0.5,border =javax.swing.plaf.BorderUIResource$CompoundBorderU IResource@32fb4f,flags=296,maximumSize=,minimumSiz e=,preferredSize=,defaultIcon=,disabledIcon=,disab ledSelectedIcon=,margin=javax.swing.plaf.InsetsUIR esource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rol loverEnabled=true,rolloverIcon=,rolloverSelectedIc on=,selectedIcon=,text=,defaultCapable=true]
103502 [AWT-EventQueue-0] WARN query.JRJdbcQueryExecuter - The supplied java.sql.Connection object is null.

[/errore]