Hi Everyone,

Happy 2013 to all.I'm using JOption to print a table, how do I align the columns? I am using a single variable for the JOption. Example:

1 Milk-Anchor 100.00 100.00
10 Del Monte-Tomato Sauce 1000.00 1000.00

Any suggestion will be great.

All the best,

Recommended Answers

Take a look at: http://www.homeandlearn.co.uk/java/java_formatted_strings.html .
Use String.format() instead of System.out.printf().

Jump to Post

All 4 Replies

Thank you for the reply. Does it work in JOption. The requirement is to use JOption.

Many thanks.

Yes, it will work with JOptionPane, as long as you use String.format() to format it into a String. After that you can output the String using a JOptionPane.
I am aware that I linked to a page using System.out.printf() but it is analog for String.format().

Thank you very much for the help. Happy New Year!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.