Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Create title and header in report

  1. #1
    Join Date
    Jun 2005
    Posts
    4

    Default Create title and header in report

    Hi, I wont print data from JTable, but I have two problems with my report

    1. I know not, how I create Label in my report.
    2. I know not, how I add title to my print or export.


    I search on this website, I search on google, but any results. Please, help me. My code is


    /**
    * Creates a report definition.
    *
    * @return a report definition.
    */
    private JFreeReport createReportDefinition ()
    {

    JFreeReportBoot.getInstance().getEditableConfig().setConfigProperty("org.jfree.report.NoPrinterAvailable", "true");

    JFreeReportBoot.getInstance().start();

    final JFreeReport report = new JFreeReport();
    report.setName(getDescription());

    final PageHeader header = setHeader();
    TextFieldElementFactory factory = new TextFieldElementFactory();

    for(int x = 0; x < numberColumns; x++){



    factory.setName("T" + Integer.toString(x));
    factory.setFontSize(8 );
    System.out.println(factory.getName());
    factory.setAbsolutePosition(new Point2D.Float(x * 50, 0 ));
    factory.setMinimumSize(new FloatDimension(40, 12 ));
    factory.setColor(Color.black);
    factory.setHorizontalAlignment(ElementAlignment.CENTER);
    factory.setVerticalAlignment(ElementAlignment.CENTER);
    factory.setNullString("-");
    factory.setFieldname(columnNames[x].toString());
    System.out.println(factory.getFieldname());
    report.getItemBand().addElement(factory.createElement());
    factory.setDynamicHeight(Boolean.TRUE);
    header.addElement(factory.createElement());

    header.addElement(StaticShapeElementFactory.createHorizontalLine("line1", Color.decode("#CFCFCF"),
    new BasicStroke(2), 16 ));

    }

    return report;

    }

    ************************************************************
    private PageHeader setHeader(){


    final PageHeader header = new PageHeader();
    header.setName("Page-header");
    header.getStyle().setStyleProperty(ElementStyleSheet.MINIMUMSIZE, new FloatDimension(0, 18));
    header.getStyle().setFontDefinitionProperty(new FontDefinition("Serif", 10));
    header.setDisplayOnFirstPage(true);
    header.setDisplayOnLastPage(false);
    header.addElement(StaticShapeElementFactory.createRectangleShapeElement(null, Color.decode("#AFAFAF"), null,
    new Rectangle2D.Float(0, 0, -100, -100),
    false, true));

    final LabelElementFactory factory = new LabelElementFactory();
    factory.setName("Report-Header-Label");
    factory.setAbsolutePosition(new Point2D.Float(0, 0));
    factory.setMinimumSize(new FloatDimension(-400, 24));
    factory.setHorizontalAlignment(ElementAlignment.CENTER);
    factory.setVerticalAlignment(ElementAlignment.MIDDLE);


    for(int x =0; x < numberColumns; x++){

    factory.setText((String) columnNames[x]);
    header.addElement(factory.createElement());
    }






    return header;
    }

    **********************************************************


    protected void executeReport ()
    {
    final TableModel data = createData();//in this function I read data from JTable

    final JFreeReport report = createReportDefinition();
    report.setData(data);
    try
    {
    final PreviewDialog preview = new PreviewDialog(report);
    preview.setSize(800,600);
    preview.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    preview.setVisible(true);

    }
    catch (ReportProcessingException e)
    {
    Log.error("Can not create report ", e);
    }
    **********************************************************

    Regards

  2. #2

    Default

    Hi,

    if you need labels, just use the factory named LabelElementFactory to create them.
    If you want to add a title, just put a label in the report header for example.

    PS: don't forget to look at demos by running them (java -jar jfreereport-demo-0.XXXX.jar) read their sources (located in the source/org/jfree/report/demo directory)
    May the Moo force be with you,
    Said Mimil

    A student of JFree & Pentaho Academies,
    Cedric Pronzato

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.