*
The moose likes Java in General and the fly likes Formatting string for printing 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 string for printing" Watch "Formatting string for printing" New topic
Author

Formatting string for printing

vivek ja
Ranch Hand

Joined: Feb 24, 2005
Posts: 80
I am trying to print out something using my java program.
I was the printed page to be 2 colums.

For this, I need some mechanism where i specify that it should print in 2 columns and it has to print in the first column and continue in the second

I dont have any idea how this can be done, can someone pls guide me.
Thank you!
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Print to screen/ file?
this will work for foo not being longer than 7 characters:
System.out.println (foo + "\ŧ" + bar);
If you calculate the longest value for the first column, you may fill the right number of tabs to get two columns.

If you print to the printer, you need to specify coordinates allthough, don't you?


http://home.arcor.de/hirnstrom/bewerbung
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
What version of Java are you using? If you are using JDK 1.5, then there is a PrintWriter class that provides a printf() method that behaves similarly to the printf() function from C/C++. It allows for some very sophisticated formatting. You should look at the Javadocs for more information.

Layne


Java API Documentation
The Java Tutorial
vivek ja
Ranch Hand

Joined: Feb 24, 2005
Posts: 80
Actually I have a faxing f unctionality.
I am using a third party tool that will fax whatever string I am sending.
So my string has to be formatted before calling that fax API.

I am trying to format it using the \n and \t characters wherever needed.
The foo+\t+bar adds tabs, but how can I specify that I want 2 columns?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by vivek ja:
Actually I have a faxing f unctionality.
I am using a third party tool that will fax whatever string I am sending.
So my string has to be formatted before calling that fax API.

I am trying to format it using the \n and \t characters wherever needed.
The foo+\t+bar adds tabs, but how can I specify that I want 2 columns?


Since you probably need to format to a String, you can wrap a StringWriter with the PrintWriter I mentioned before. Whether you do this or use explicit tab characters, there is no way to explicitly state there are two columns. As long as the contents of each column have a limited width, either using PrintWriter or \t characters should work.

Layne
 
jQuery in Action, 2nd edition
 
subject: Formatting string for printing
 
Similar Threads
Continuation of basic principles
EL expression
Why int variable as it be decleared can't used " ^ " with number?
Postfix operator
Doubt in question