Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Set background in first row in report

  1. #1
    Join Date
    Jun 2005
    Posts
    4

    Default Set background in first row in report

    Hi, I have report created from JTable. To first row report I add name columns from TableHeader my JTable. I have question, can I set backgrount this first row(font or complet backgrout)? Thanks

    Regards

    Aldik


    My code for create report is


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

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


    // factory.setColor(Color.RED);
    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));






    }

  2. #2
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Hi,

    the column names should be added as Labels to either the report header (or if you want them to repeat on each subsequent page) to the group header of the default group (that is a group, that has no fields defined and which therefore spans the complete report).

    Mixing bulk data and column names (=meta data) is definitly no good idea.

    The background can be defined by adding a rectangle element to the band.

    Regards,
    Thomas

  3. #3
    Join Date
    Jun 2005
    Posts
    4

    Default

    Hi, thanks for your answer. I know, my result is hack, no good idea. Please, help me. I create function


    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", 8 ));
    header.setDisplayOnFirstPage(true);
    header.setDisplayOnLastPage(false);
    header.addElement(StaticShapeElementFactory.createRectangleShapeElement(null, Color.decode("#AFAFAF"), null,
    new Rectangle2D.Float(0, 0, -100, -100),
    false, true));


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

    header.addElement((Element) columnNames[x]);//this is wrong, how I can add to header element
    }




    return header;
    }


    ****************************************************
    and I re-write my primary code

    /**
    * 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;

    }

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


    In Object[] columnNames I have description my TableHeader



    Regards

  4. #4
    Join Date
    Nov 2005
    Posts
    23

    Default

    Hi,

    to put your column headers on the page header of your report try this:

    Code:
     //here you have the header&#58;
    PageHeader header = report.getPageHeader&#40;&#41;;
    
    // put a background element on the header spanning the hole pagewidth
    header.addElement&#40;StaticShapeElementFactory.createRectangleShapeElement&#40;"_background_element_",...&#41;&#41;;
    
    // put your column labels and columns on your report
    for&#40;int x = 0; x < numberColumns; x++&#41;&#123; 
      // put the column labels on the header
      header.addElement&#40;LabelElementFactory.createLabelElement&#40;...&#41;&#41;;
    
      // put your column on the itemband
      report.getItemBand&#40;&#41;.addElement&#40;...&#41;;
    &#125;

    Regards
    klaus

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.