gpt4 book ai didi

jasper-reports - 如何让 jasper 报告在 JDialog 的顶部?

转载 作者:行者123 更新时间:2023-12-04 06:42:26 24 4
gpt4 key购买 nike

我使用 Netbeans 的 jasper 报告插件制作报告,我使用 JDialog 中的一个按钮来显示我的 jasper 报告。但是报告显示在我的 JDialog 上,这里有什么问题?

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                
// TODO add your handling code here:
Map<String, Object> params = new HashMap <>();
try {
Connection kon = DriverManager.getConnection(database,user,pass);
JasperDesign jasperDesign = JRXmlLoader.load("Myreports.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, kon);
JasperViewer jasperViewer = new JasperViewer(jasperPrint, false);
jasperViewer.setTitle("My Reports");
jasperViewer.setVisible(true);
} catch (SQLException | JRException e){
e.printStackTrace();
}
}

我是这样添加 setModal 的:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                
// TODO add your handling code here:
Map<String, Object> params = new HashMap <>();
try {
Connection kon = DriverManager.getConnection(database,user,pass);
JasperDesign jasperDesign = JRXmlLoader.load("Myreports.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, kon);
JasperViewer jasperViewer = new JasperViewer(jasperPrint, false);
jasperViewer.setTitle("My Reports");
setModal(false);
jasperViewer.setVisible(true);
setModal(true);
} catch (SQLException | JRException e){
e.printStackTrace();
}
}

我的报告在 JDialog 上显示为顶部,但其中的按钮不起作用。

最佳答案

您可以使用此代码使 JR 显示为 JDialog:

//after creating jasperViewer//
jasperViewer = new JasperViewer(jasperPrint, false);
JDialog dialog = new JDialog(this);//the owner
dialog.setContentPane(jasperViewer.getContentPane());
dialog.setSize(jasperViewer.getSize());
dialog.setTitle("XXXXX");
dialog.setIconImage(Toolkit.getDefaultToolkit().getImage(
getClass().getResource("URL IMG")));
dialog.setVisible(true);

关于jasper-reports - 如何让 jasper 报告在 JDialog 的顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31468428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com