aspose file tools*
The moose likes Java in General and the fly likes Formatting text documents in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Formatting text documents in Java?" Watch "Formatting text documents in Java?" New topic
Author

Formatting text documents in Java?

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
I want to generate a report that has preset columns. I tried using tabs but each row is still misaligned. How can I align the rows if the text is variable size?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can pad the strings to a fixed size. I have a little library to right and left justify strings for this kind of thing.

I patterned all my string helper methods after the REXX langauge which has lovely string handling


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
Thanks, is this util class avalaible in Java?
Tomas Hirsch
Greenhorn

Joined: Sep 01, 2004
Posts: 1
I also made a small hack to get some text formatting.
I'll put it up on:
http://www.fos.su.se/~tompa/JAVA/FormatString.txt
so you can check it out.
It's a private class like Math, so you invoke it by saying:
FormatString.xxxxAdjust( String foo, int bar )
where
xxxx = right, left, or middle.
foo = the string you wnat to adjust.
bar = the number of characters long you want the formatted text to be.
Best regards!
Tomas
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
For grins, as an optional argument specify what character or string to use for padding. It's cool to put leading zeros or center a string for a heading or eyecatcher:
 
Consider Paul's rocket mass heater.
 
subject: Formatting text documents in Java?