简体   繁体   中英

How to increase width or height of JasperViewer (Hard coded)?

This is my code

static Connection connHealthInfoSystem = DBConnection.conn("health_info_system");
public static void printDisplayable(String reportPath, Map parameter) {
    JasperDesign jd;
    try {
        jd = JRXmlLoader.load(reportPath);
        JasperReport jr = JasperCompileManager.compileReport(jd);
        JasperPrint jp = JasperFillManager.fillReport(jr, parameter, connHealthInfoSystem);
        JasperViewer.viewReport(jp, false);
    } catch (JRException ex) {
        Logger.getLogger(JasperPrinting.class.getName()).log(Level.SEVERE, null, ex);
    }
}

Based on the current code that I have, how can I increase the size of the width of my report when it pops up?

try jd.setPageWidth(999); before JasperCompileManager.compileReport(jd);

Don't use the static method JasperViewer.viewReport(jp, false); , since this way you don't have control of JasperViewer object instead instance your own JasperViewer

JasperViewer viewer = new JasperViewer(jp, false);

JasperViewer extends JFrame so you can set size, location as for any JFrame , just remember to set it visibile when your done.

Example

JasperViewer viewer = new JasperViewer(jp, false);
viewer.setLocationRelativeTo(null); //You can set location
viewer.setSize(new Dimension(1000,600)); //You can set size or you set preferredSize and the pack it.
viewer.setVisible(true); //When you are ready, you set the frame to be visibile

我从来没有用过这个,但是如果你只看代码,硬编码的东西是"health_info_system"所以我想你可以使用一些资源文件夹并获取它 mby .. 或者只是让它成为一个常量。

private static final String HEALTH_INFO_SYSTEM_DB = "health_info_system";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM