Jump to content
We've recently updated our Privacy Statement, available here ×

Formatting - Centre > 1 Field Across Page


liz

Recommended Posts

Hi guys,

New to ireports and stuck already! I'm using ireports V1.2.7. and would be grateful of some formatting assistance.

Trying to format 2 fields differently and align them together centered on the page. For example:

 

Mr Joe Bloggs (born 21 November 1970)

 

 

I have a String variable, $V{NAME_COMBO}, that has the name field and the opening bracket and the word born. $F{name} + " (born "

 

 

I have a field $F{date_of_birth} that is a java.sql.Timestamp, format pattern = d MMMMM yyyy).

 

 

As these are 2 fields I can align them but can never be sure they will jointly be centered on the page as the NAME_COMBO size will change dynamically.

 

 

I've tried making a variable with all the data but I cannot format the date in this. Is there any way to make a composite field of the 2 or some other way of joining them?

 

 

Any ideas would be gratefully received.

Thanks in anticipation.

Liz

Post edited by: liz, at: 2007/05/01 13:26

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

hi, liz!

welcome to the forum.

 

if you want to have two fields always centered in one line just use one text field that contains the two fields ($F), variables ($V), or parameters ($P) - for the sake of simplicity, let's collectively refer to them here as your 'data fields'.

 

i'm not entirely sure what your purpose is for using a variable to contain the field and the text but try this out first:

 

1. create a wide and tall enough text field approximately where you want the information to be centered (we'll take care of the exact placement later). this is where you will place your data fields.

 

2. you practically just have to join the contents of your two fields in a single text field. right click on your text field, click properties and go to the text field tab. enter the following in the text field expression box:

 

$F{name} + " (born " + $F{date_of_birth} + ")"

 

you actually can enter this directly on your text field by double clicking it but i think its clearer to enter it using the properties window. besides, you'll be changing the settings to this text field element through the properties window.

note that you have to contatenate (join) the fields and text strings with the plus sign (+) as well as enclose the text strings in double or single quotes for this to display correctly.

make sure that the text field expression class is set to java.lang.string.

 

3. click on the font tab.

in the horizontally align dropdown list, select center.

set all you other font preferences while you're in this tab.

 

4. check if your elements formatting toolbar is displayed (the toolbar with several blue boxes and green arrows).

if not, go to your iReport menu bar, click view > toolbars > elements formatting toolbar (must be checked). it would serve you well if you take time to play around and experiment with the available tools.

 

5. click on the text field you just created to select it.

on the elements formatting toolbar click "center between margins" (the blue vertical rectangle between the two green horizontal arrows). This will horizontally center your text field on your page. click this button after horizontally resizing this text field so that it will be centered. you could also click the "enlarge between margins" button to make your text field span the whole width of your detail band (that's the button with the two horizontal arrows inside the blue rectangle).

You could also make fine adjustments to the position of your text field in the common tab of the properties window. you could also make adjustments to the size of your text element in this tab.

 

i believe that's it! :)

let us know if this helped you.

don't be discouraged if you run into problems along the way... experiment and enjoy discovering new things.

in time, your discoveries might also help others.

 

 

Edwin

Post edited by: edwin, at: 2007/05/03 18:34

Link to comment
Share on other sites

Thanks for this Edwin, but I'm afraid it does not resolve my date formatting problem.

Essentially what I want to end up with is a centered across the page piece of text:

Mr Joe Bloggs (born 23 March 1972)

 

 

$F name = java.lang.string = Mr Joe Bloggs

(born is free text in quotes

$F date_of_birth = java.sql.Timestamp 23 March 1972 with a format pattern of d MMMMM yyyy)

) closing bracket is free text in quotes

 

$V COMBO_FIELD = $F{name}+ " (born " + $F(date_of_birth) + ")"

 

Output does not have the required date format:

Mr Joe Bloggs (born 1972-0323 00:00:00.0)

 

 

I can get it to display correctly by using the 2 fields described in my original posting but then I can't centre across the page.

 

Can iReports do both at the same time? :S

Link to comment
Share on other sites

liz,

 

the code that jys posted is the one you need.

just place a dollar sign ($) before F{date_of_birth} which is just a typo.

the code i previously posted will not give you the correct date format.

also, i now realize what your purpose was for placing everything in a variable. :)

just ignore my last post about sending me your .jrxml file.

hope jys' code is the one you were looking for.

have fun!

 

 

jys,

 

a thumbs up for you! :)

 

 

edwin

Link to comment
Share on other sites

liz,

 

on your question:

"I can get it to display correctly by using the 2 fields described in my original posting but then I can't centre across the page... Can iReports do both at the same time?"

 

the answer is yes - as demonstrated by the code given by jys. in fact, you have the option to do the whole expression on one text field or you can chop up your expression into as many valid parts as you want... for whatever reason that may serve you. it really depends on your preferences and requirements. i personally find it easier, most of the time to place text i need to center into a single text field (or static text element). i also think that the less elements used the better it is for the report. ... which reminds me, i need to post a question related to this. :)

 

 

edwin

Post edited by: edwin, at: 2007/05/07 15:21

Link to comment
Share on other sites

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...