简体   繁体   中英

How to get column under the title in DynamicReports?

在此处输入图片说明

I need to get the column right under the title and i don't need any gaps in between. And how to set width to the column? I have given setWidth(50) but its not getting and the border is covering entire right side of the page

Here is my code:

public class DynamicReport {
    public static void main(String[] args) {
        Connection connection = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/marketing_database","root","root");
        } catch (SQLException e) {
            e.printStackTrace();
            return;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }

        JasperReportBuilder report = DynamicReports.report();//a new report
        StyleBuilder plainStyle = stl.style().setFontName("FreeUniversal");

        StyleBuilder boldStyle = stl.style(plainStyle).bold().setBorder(stl.pen1Point());
        StyleBuilder col1style = stl.style().setBorder(stl.pen1Point());

        report
          .title(Components.text("Tax Invoice Cum Delivery Challan").setStyle(boldStyle)
          .setHorizontalAlignment(HorizontalAlignment.CENTER))
          .columns(col.column("", "companyName", type.stringType()).setWidth(50).setStyle(col1style))
          .pageFooter(Components.pageXofY())
          .setDataSource("SELECT companyName FROM marketing_database.company_profile", 
                                      connection);
        try {
            report.show();
            report.toPdf(new FileOutputStream("c:/report.pdf"));
        } catch (DRException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
      }
}

Any help in this will be appreciated

UPDATED:

I got how to set the width for a column. I used this code:

 col.column("", "companyName", type.stringType()).setFixedWidth(20)
report



        .columnHeader(//title of the report


              Components.text("Tax Invoice Cum Delivery Challan").setStyle(boldStyle).setFixedHeight(10)
              .setHorizontalAlignment(HorizontalAlignment.CENTER))

             .columns(
                     col.column("", "companyName", type.stringType()).setFixedWidth(200).setStyle(col1style))

              .pageFooter(Components.pageXofY())//show page number on the page footer
              .setDataSource("SELECT companyName FROM marketing_database.company_profile", 
                                      connection);

        try {
                    //show the report
            report.show();

                    //export the report to a pdf file
            report.toPdf(new FileOutputStream("c:/report.pdf"));
        } catch (DRException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
      }

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