Jump to content
JasperReports Library 7.0 is now available ×

Jasper Report alignment problem


2004 IR Help

Recommended Posts

By: Radha - radharani

Jasper Report alignment problem

2005-08-23 00:21

Hi,

 

I am working on Jasper Reports for the past 6 months. I am using static design for some reports and dynamic design for some reports. but in both cases sometimes the report looks very ugly because the lines are not aligned properly (especially when it has large datas or when the data length is longer than the textfield size. i tried so many things like stretchwithoverflow, stretchtype, position type.

but nothing works. below is one of my dynamic design code. i wanted to attach the snapshot of the report. but i dont know how to attach a file in this forum.

 

Please help me. I am struggling with this for the past few months.any help would be appreciated.

 

 

 

public static JasperDesign getJasperDesign(ArrayList SiteArr) throws JRException

{

 

int i;

int j;

int n= SiteArr.size();

JRDesignField field;

JRBaseBox b;

JRDesignStaticText statictext;

JRDesignBand band;

JRDesignLine line;

JRDesignExpression expr;

JRDesignTextField textField;

JRDesignExpression expression,exp;

JRDesignRectangle rectangle;

JRDesignParameter parameter;

//JasperDesign

JasperDesign jasperDesign = new JasperDesign();

jasperDesign.setName("TunesDesignReport");

jasperDesign.setPageWidth(1100);

jasperDesign.setPageHeight(842);

jasperDesign.setColumnWidth(535);

jasperDesign.setColumnSpacing(0);

jasperDesign.setLeftMargin(20);

jasperDesign.setRightMargin(20);

jasperDesign.setTopMargin(20);

jasperDesign.setBottomMargin(20);

jasperDesign.setTitleNewPage(false);

jasperDesign.setSummaryNewPage(false);

 

 

//Fonts

JRDesignReportFont normalFont = new JRDesignReportFont();

normalFont.setName("Arial_Normal");

normalFont.setDefault(true);

normalFont.setFontName("Arial");

normalFont.setSize(10);

normalFont.setPdfFontName("Helvetica");

normalFont.setPdfEncoding("Cp1252");

normalFont.setPdfEmbedded(false);

jasperDesign.addFont(normalFont);

 

JRDesignReportFont boldFont = new JRDesignReportFont();

boldFont.setName("Arial_Bold");

boldFont.setDefault(false);

boldFont.setFontName("Arial");

boldFont.setSize(10);

boldFont.setBold(true);

boldFont.setPdfFontName("Helvetica-Bold");

boldFont.setPdfEncoding("Cp1252");

boldFont.setPdfEmbedded(false);

jasperDesign.addFont(boldFont);

 

//Parameters

parameter = new JRDesignParameter();

parameter.setName("Customer");

parameter.setValueClass(java.lang.String.class);

jasperDesign.addParameter(parameter);

 

parameter = new JRDesignParameter();

parameter.setName("Provider");

parameter.setValueClass(java.lang.String.class);

jasperDesign.addParameter(parameter);

 

parameter = new JRDesignParameter();

parameter.setName("Cstr");

parameter.setValueClass(java.lang.String.class);

jasperDesign.addParameter(parameter);

 

parameter = new JRDesignParameter();

parameter.setName("start");

parameter.setValueClass(java.lang.String.class);

jasperDesign.addParameter(parameter);

 

parameter = new JRDesignParameter();

parameter.setName("end");

parameter.setValueClass(java.lang.String.class);

jasperDesign.addParameter(parameter);

 

parameter = new JRDesignParameter();

parameter.setName("page");

parameter.setValueClass(java.lang.String.class);

jasperDesign.addParameter(parameter);

 

 

JRDesignParameter param = new JRDesignParameter();

param.setName("Priv");

param.setValueClass(com.onmobile.tools.contentdistribution.server.UserProfile.class);

jasperDesign.addParameter(param);

 

 

//Fields

field = new JRDesignField();

field.setName("Tunes");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("Category");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("TC_Total");

field.setValueClass(java.lang.Integer.class);

jasperDesign.addField(field);

 

for(i=0;i<n;++i){

field = new JRDesignField();

field.setName("TC_"+SiteArr.get(i).toString());

field.setValueClass(java.lang.Integer.class);

jasperDesign.addField(field);

}

for(i=0;i<n;++i){

field = new JRDesignField();

field.setName("SI_"+SiteArr.get(i).toString());

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

}

field = new JRDesignField();

field.setName("CLIP_NAME");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("PROVIDER_NAME");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("ALBUM");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("CLIP_PROMO_ID");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("LABEL_NAME");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("ROYALTY_NAME");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

//Title

band = new JRDesignBand();

band.setHeight(60);

 

JRDesignReportFont bigFont = new JRDesignReportFont();

bigFont.setName("Arial_Normal");

bigFont.setDefault(true);

bigFont.setFontName("Arial");

bigFont.setSize(18);

bigFont.setPdfFontName("Helvetica");

bigFont.setPdfEncoding("Cp1252");

bigFont.setPdfEmbedded(false);

bigFont.setItalic(true);

bigFont.setBold(true);

 

textField = new JRDesignTextField();

textField.setX(0);

textField.setY(4);

textField.setWidth(500);

textField.setHeight(50);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$P{Customer}.toUpperCase()+" - TUNES LIST "");

textField.setExpression(expression);

 

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

 

textField.setPrintWhenDetailOverflows(false);

textField.setStretchWithOverflow(false);

textField.setFont(bigFont);

band.addElement(textField);

//link for viewing provider report

textField = new JRDesignTextField();

textField.setX(510);

textField.setY(4);

textField.setWidth(400);

textField.setHeight(50);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText(""Click here for tune providers"");

textField.setExpression(expression);

expr = new JRDesignExpression();

expr.setValueClass(java.lang.String.class);

expr.setText("$P{Priv}.getURL("rbt_tune_xl.jsp?page=xl&customer="+$P{Customer}+"&Startdate="+$P{start}+"&Enddate="+$P{end}+"&Cstr="+$P{Cstr})");

textField.setHyperlinkReferenceExpression(expr);

exp = new JRDesignExpression();

exp.setValueClass(java.lang.Boolean.class);

exp.setText("new Boolean($P{page}.equals("html"))");

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setHyperlinkType(JRHyperlink.HYPERLINK_TYPE_REFERENCE);

textField.setHyperlinkTarget(JRHyperlink.HYPERLINK_TARGET_SELF);

textField.setPrintWhenExpression(exp);

textField.setPrintWhenDetailOverflows(false);

textField.setStretchWithOverflow(false);

textField.setFont(boldFont);

band.addElement(textField);

 

jasperDesign.setTitle(band);

 

//Page header

band = new JRDesignBand();

band.setHeight(0);

band.setSplitAllowed(true);

jasperDesign.setPageHeader(band);

 

//Column header

band = new JRDesignBand();

band.setHeight(0);

band.setSplitAllowed(true);

jasperDesign.setColumnHeader(band);

 

//groupheader

JRDesignGroup group = new JRDesignGroup();

group.setName("ReportGroup");

group.setMinHeightToStartNewPage(60);

group.setStartNewColumn(false);

band = new JRDesignBand();

band.setHeight(25);

band.setSplitAllowed(false);

b=new JRBaseBox();

b.setBorder((byte)1);

b.setBorderColor(Color.BLACK);

 

textField= new JRDesignTextField();

textField.setX(0);

textField.setY(0);

textField.setWidth(250);

textField.setHeight(25);

//statictext.setPrintRepeatedValues(true);

textField.setStretchWithOverflow(true);

textField.setPrintWhenDetailOverflows(false);

textField.setPrintInFirstWholeBand(false);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_CENTER);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setHyperlinkType(JRHyperlink.HYPERLINK_TYPE_REFERENCE);

textField.setHyperlinkTarget(JRHyperlink.HYPERLINK_TARGET_SELF);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText(""TUNES"");

textField.setExpression(expression);

 

expr = new JRDesignExpression();

expr.setValueClass(java.lang.String.class);

expr.setText("$P{Priv}.getURL("rbt_tunes_site.jsp?page=html&customer="+$P{Customer}+"&circle=TUNES")");

textField.setHyperlinkReferenceExpression(expr);

 

textField.setFont(boldFont);

textField.setBox(b);

textField.setForecolor(Color.DARK_GRAY);

band.addElement(textField);

 

 

b=new JRBaseBox();

b.setRightBorder((byte)1);

b.setTopBorder((byte)1);

b.setBottomBorder((byte)1);

b.setRightBorderColor(Color.BLACK);

b.setBottomBorderColor(Color.BLACK);

b.setTopBorderColor(Color.BLACK);

 

statictext= new JRDesignStaticText();

statictext.setX(250);

statictext.setY(0);

statictext.setWidth(250);

statictext.setHeight(25);

statictext.setText("CATEGORY");

//statictext.setPrintRepeatedValues(true);

statictext.setPrintWhenDetailOverflows(false);

statictext.setPrintInFirstWholeBand(false);

statictext.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

statictext.setRotation(JRTextElement.ROTATION_NONE);

statictext.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

statictext.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

statictext.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

statictext.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//statictext.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//statictext.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

 

statictext.setFont(boldFont);

statictext.setBox(b);

statictext.setForecolor(Color.DARK_GRAY);

band.addElement(statictext);

 

textField= new JRDesignTextField();

textField.setX(500);

textField.setY(0);

textField.setWidth(50);

textField.setHeight(25);

String total="TOTAL";

 

//statictext.setPrintRepeatedValues(true);

textField.setStretchWithOverflow(true);

textField.setPrintWhenDetailOverflows(false);

textField.setPrintInFirstWholeBand(false);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_CENTER);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setHyperlinkType(JRHyperlink.HYPERLINK_TYPE_REFERENCE);

textField.setHyperlinkTarget(JRHyperlink.HYPERLINK_TARGET_SELF);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText(""TOTAL"");

textField.setExpression(expression);

 

expr = new JRDesignExpression();

expr.setValueClass(java.lang.String.class);

expr.setText("$P{Priv}.getURL("rbt_tunes_site.jsp?page=html&customer="+$P{Customer}+"&circle=TOTAL")");

textField.setHyperlinkReferenceExpression(expr);

 

textField.setFont(boldFont);

textField.setBox(b);

textField.setForecolor(Color.DARK_GRAY);

band.addElement(textField);

 

for(i=0,j=0;i<n;++i,j=j+50){

 

textField = new JRDesignTextField();

textField.setHyperlinkType(JRHyperlink.HYPERLINK_TYPE_REFERENCE);

textField.setHyperlinkTarget(JRHyperlink.HYPERLINK_TARGET_SELF);

textField.setX(550+j);

textField.setY(0);

textField.setWidth(50);

textField.setHeight(25);

 

textField.setPrintRepeatedValues(true);

textField.setPrintWhenDetailOverflows(true);

textField.setStretchWithOverflow(true);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setRotation(JRTextElement.ROTATION_NONE);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setForecolor(Color.DARK_GRAY);

textField.setFont(boldFont);

textField.setBox(b);

 

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

String sitename=(SiteArr.get(i).toString());

String siteupper= sitename.toUpperCase();

expression.setText("""+siteupper+""");

textField.setExpression(expression);

 

expr = new JRDesignExpression();

expr.setValueClass(java.lang.String.class);

expr.setText("$P{Priv}.getURL("rbt_tunes_site.jsp?page=html&customer="+$P{Customer}+"&circle="+""+sitename+"")");

textField.setHyperlinkReferenceExpression(expr);

 

band.addElement(textField);

}

//Tunes Provider

exp= new JRDesignExpression();

exp.setValueClass(java.lang.Boolean.class);

exp.setText("new Boolean($P{Provider}.equals("yes"))");

 

statictext= new JRDesignStaticText();

statictext.setX(550+j);

statictext.setY(0);

statictext.setWidth(150);

statictext.setHeight(25);

statictext.setText("CLIP_NAME");

//statictext.setPrintRepeatedValues(true);

statictext.setPrintWhenDetailOverflows(false);

statictext.setPrintInFirstWholeBand(false);

statictext.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

statictext.setRotation(JRTextElement.ROTATION_NONE);

statictext.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

statictext.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

statictext.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

statictext.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//statictext.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//statictext.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

statictext.setFont(boldFont);

statictext.setBox(b);

statictext.setForecolor(Color.DARK_GRAY);

statictext.setPrintWhenExpression(exp);

band.addElement(statictext);

 

j=j+150;

statictext= new JRDesignStaticText();

statictext.setX(550+j);

statictext.setY(0);

statictext.setWidth(100);

statictext.setHeight(25);

statictext.setText("CLIP_PROMO_ID");

//statictext.setPrintRepeatedValues(true);

statictext.setPrintWhenDetailOverflows(false);

statictext.setPrintInFirstWholeBand(false);

statictext.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

statictext.setRotation(JRTextElement.ROTATION_NONE);

statictext.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

statictext.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

statictext.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

statictext.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//statictext.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//statictext.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

statictext.setFont(boldFont);

statictext.setBox(b);

statictext.setForecolor(Color.DARK_GRAY);

statictext.setPrintWhenExpression(exp);

band.addElement(statictext);

 

j=j+100;

statictext= new JRDesignStaticText();

statictext.setX(550+j);

statictext.setY(0);

statictext.setWidth(150);

statictext.setHeight(25);

statictext.setText("ALBUM");

//statictext.setPrintRepeatedValues(true);

statictext.setPrintWhenDetailOverflows(false);

statictext.setPrintInFirstWholeBand(false);

statictext.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

statictext.setRotation(JRTextElement.ROTATION_NONE);

statictext.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

statictext.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

statictext.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

statictext.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//statictext.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//statictext.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

statictext.setFont(boldFont);

statictext.setBox(b);

statictext.setForecolor(Color.DARK_GRAY);

statictext.setPrintWhenExpression(exp);

band.addElement(statictext);

 

j=j+150;

statictext= new JRDesignStaticText();

statictext.setX(550+j);

statictext.setY(0);

statictext.setWidth(150);

statictext.setHeight(25);

statictext.setText("PROVIDER_NAME");

//statictext.setPrintRepeatedValues(true);

statictext.setPrintWhenDetailOverflows(false);

statictext.setPrintInFirstWholeBand(false);

statictext.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

statictext.setRotation(JRTextElement.ROTATION_NONE);

statictext.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

statictext.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

statictext.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

statictext.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//statictext.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//statictext.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

statictext.setFont(boldFont);

statictext.setBox(b);

statictext.setForecolor(Color.DARK_GRAY);

statictext.setPrintWhenExpression(exp);

band.addElement(statictext);

 

j=j+150;

statictext= new JRDesignStaticText();

statictext.setX(550+j);

statictext.setY(0);

statictext.setWidth(150);

statictext.setHeight(25);

statictext.setText("LABEL_NAME");

//statictext.setPrintRepeatedValues(true);

statictext.setPrintWhenDetailOverflows(false);

statictext.setPrintInFirstWholeBand(false);

statictext.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

statictext.setRotation(JRTextElement.ROTATION_NONE);

statictext.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

statictext.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

statictext.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

statictext.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//statictext.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//statictext.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

statictext.setFont(boldFont);

statictext.setBox(b);

statictext.setForecolor(Color.DARK_GRAY);

statictext.setPrintWhenExpression(exp);

band.addElement(statictext);

 

j=j+150;

statictext= new JRDesignStaticText();

statictext.setX(550+j);

statictext.setY(0);

statictext.setWidth(150);

statictext.setHeight(25);

statictext.setText("ROYALTY_NAME");

//statictext.setPrintRepeatedValues(true);

statictext.setPrintWhenDetailOverflows(false);

statictext.setPrintInFirstWholeBand(false);

statictext.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

statictext.setRotation(JRTextElement.ROTATION_NONE);

statictext.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

statictext.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

statictext.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

statictext.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//statictext.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

//statictext.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

statictext.setFont(boldFont);

statictext.setBox(b);

statictext.setForecolor(Color.DARK_GRAY);

statictext.setPrintWhenExpression(exp);

band.addElement(statictext);

 

 

group.setGroupHeader(band);

//group footer

band = new JRDesignBand();

band.setHeight(0);

band.setSplitAllowed(true);

group.setGroupFooter(band);

jasperDesign.addGroup(group);

 

 

//Detail

band = new JRDesignBand();

band.setHeight(25);

band.setSplitAllowed(true);

b =new JRBaseBox();

b.setLeftBorder((byte)1);

b.setRightBorder((byte)1);

b.setBottomBorder((byte)1);

b.setLeftBorderColor(Color.BLACK);

b.setBottomBorderColor(Color.BLACK);

 

textField = new JRDesignTextField();

textField.setX(0);

textField.setY(0);

textField.setWidth(250);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setPrintWhenDetailOverflows(false);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setStretchWithOverflow(true);

textField.setPrintInFirstWholeBand(false);

 

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{Tunes}");

textField.setExpression(expression);

textField.setBox(b);

band.addElement(textField);

 

textField = new JRDesignTextField();

textField.setX(250);

textField.setY(0);

textField.setWidth(250);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setFont(normalFont);

textField.setPrintWhenDetailOverflows(false);

textField.setPrintInFirstWholeBand(false);

textField.setStretchWithOverflow(true);

textField.setForecolor(Color.DARK_GRAY);

 

b =new JRBaseBox();

b.setRightBorder((byte)1);

b.setBottomBorder((byte)1);

b.setRightBorderColor(Color.BLACK);

b.setBottomBorderColor(Color.BLACK);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{Category}");

textField.setBox(b);

textField.setExpression(expression);

band.addElement(textField);

 

textField = new JRDesignTextField();

textField.setX(500);

textField.setY(0);

textField.setWidth(50);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setPrintWhenDetailOverflows(false);

textField.setPrintInFirstWholeBand(false);

textField.setStretchWithOverflow(true);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setBox(b);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.Integer.class);

expression.setText("$F{TC_Total}");

textField.setExpression(expression);

band.addElement(textField);

 

for(i=0,j=0;i<n;j=j+50,++i){

textField = new JRDesignTextField();

textField.setX(550+j);

textField.setY(0);

textField.setWidth(50);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setPrintWhenDetailOverflows(false);

textField.setPrintInFirstWholeBand(false);

textField.setStretchWithOverflow(true);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setBox(b);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.Integer.class);

String sitename=SiteArr.get(i).toString();

expression.setText("$F{TC_"+sitename+"}");

textField.setExpression(expression);

band.addElement(textField);

}

//Tunes Provider

exp= new JRDesignExpression();

exp.setValueClass(java.lang.Boolean.class);

exp.setText("new Boolean($P{Provider}.equals("yes"))");

 

textField = new JRDesignTextField();

textField.setX(550+j);

textField.setY(0);

textField.setWidth(150);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setPrintWhenDetailOverflows(false);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setStretchWithOverflow(true);

textField.setPrintInFirstWholeBand(false);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{CLIP_NAME}");

textField.setExpression(expression);

textField.setPrintWhenExpression(exp);

textField.setBox(b);

band.addElement(textField);

 

j= 150+j;

textField = new JRDesignTextField();

textField.setX(550+j);

textField.setY(0);

textField.setWidth(100);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setPrintWhenDetailOverflows(false);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setStretchWithOverflow(true);

textField.setPrintInFirstWholeBand(false);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{CLIP_PROMO_ID}");

textField.setExpression(expression);

textField.setPrintWhenExpression(exp);

textField.setBox(b);

band.addElement(textField);

 

j=100+j;

textField = new JRDesignTextField();

textField.setX(550+j);

textField.setY(0);

textField.setWidth(150);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setPrintWhenDetailOverflows(false);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setStretchWithOverflow(true);

textField.setPrintInFirstWholeBand(false);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{ALBUM}");

textField.setExpression(expression);

textField.setPrintWhenExpression(exp);

textField.setBox(b);

band.addElement(textField);

 

j=150+j;

textField = new JRDesignTextField();

textField.setX(550+j);

textField.setY(0);

textField.setWidth(150);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setPrintWhenDetailOverflows(false);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setStretchWithOverflow(true);

textField.setPrintInFirstWholeBand(false);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{PROVIDER_NAME}");

textField.setExpression(expression);

textField.setPrintWhenExpression(exp);

textField.setBox(b);

band.addElement(textField);

 

j=150+j;

textField = new JRDesignTextField();

textField.setX(550+j);

textField.setY(0);

textField.setWidth(150);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setPrintWhenDetailOverflows(false);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setStretchWithOverflow(true);

textField.setPrintInFirstWholeBand(false);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{LABEL_NAME}");

textField.setExpression(expression);

textField.setPrintWhenExpression(exp);

textField.setBox(b);

band.addElement(textField);

 

j=150+j;

textField = new JRDesignTextField();

textField.setX(550+j);

textField.setY(0);

textField.setWidth(150);

textField.setHeight(25);

textField.setRotation(JRTextElement.ROTATION_NONE);

textField.setStretchType(JRElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

//textField.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

//textField.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);

textField.setTextAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);

textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);

textField.setPrintWhenDetailOverflows(false);

textField.setFont(normalFont);

textField.setForecolor(Color.DARK_GRAY);

textField.setStretchWithOverflow(true);

textField.setPrintInFirstWholeBand(false);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{ROYALTY_NAME}");

textField.setExpression(expression);

textField.setPrintWhenExpression(exp);

textField.setBox(b);

band.addElement(textField);

 

 

 

jasperDesign.setDetail(band);

 

 

//Column footer

band = new JRDesignBand();

band.setHeight(0);

band.setSplitAllowed(true);

jasperDesign.setColumnFooter(band);

 

//Page footer

band = new JRDesignBand();

band.setHeight(0);

band.setSplitAllowed(true);

jasperDesign.setPageFooter(band);

 

//Summary

band = new JRDesignBand();

band.setHeight(0);

band.setSplitAllowed(true);

jasperDesign.setSummary(band);

 

//last Page footer

band = new JRDesignBand();

band.setHeight(0);

band.setSplitAllowed(true);

jasperDesign.setLastPageFooter(band);

 

 

 

 

return jasperDesign;

}

 

Thanks in advance.

 

 

 

 

By: alanHardwick - alan314

RE: Jasper Report alignment problem

2005-08-23 01:59

I do something similar and never had alignment problems.

In one of my reports I have created the below static

method for adding text fields to my jrPrint object, maybe this will help.. I suggest you do something similar

for clarity of code... (However you will have to use your

jasperDesign object instead)...

 

Am not sure if this helps much but here is my code:-

 

 

private static JRPrintPage jrTextField(JRPrintPage page, int left, int top, int height, int width, String text,

JRDesignReportFont font, String align) {

JRPrintText textField = new JRBasePrintText();

textField.setX(left);

textField.setY(top);

textField.setWidth(width);

textField.setHeight(height);

 

if (align.equals("R"))

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

else if (align.equals("L"))

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

else

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_CENTER);

 

textField.setLineSpacingFactor(1);

 

textField.setFont(font);

textField.setText(text);

page.addElement(textField);

return page;

}

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...