Elltz Elltz - 1 year ago 119
Java Question

Printing plain text in an aligned grid format

i would love to know the recipe to printing out text in a grid Layout format or table Layout format, where the input text are vertically aligned in a column|row type layout -(it could be any language, i am interested in the recipe)

for example suppose i have an array of Strings representing my row

String[] s = new String[]{"Adele","Taylor","Katty","Beyonce","Mariah"};
String[] s1 = new String[]{"Java","Android","Ruby","Pascal","Python"};
String[] s2 = new String[]{"Ronaldo","Ibrahimovic","Tevez","Rooney","Ronaldhino"};
String[] s3 = new String[]{"Stackoverflow","Facebook","Twitter","Amazon","Scrybasms"};

and i want to print this to a console/text file/ etc in table looking format like this

Adele Taylor Katty Beyonce Mariah
Java Android Ruby Pascal Python
Ronaldo Ibrahimovic Tevez Rooney Ronaldhino
Stackoverflow Facebook Twitter Amazon Scrybasms

but you can see they are not correctly aligned; On a gui app this is how it looks
enter image description here

and on my eclipse

enter image description here

they all have different alignments, and i do not know why hence i want a general better way of achieving what i want. thanks


Thank you all, both commenters and answerers i have solved it with the most word occurrence "MonoSpace". :)

enter image description here

Answer Source

In eclipse, it's mono-space font, like here:

aaaa bbbb cccc dddd
eeee ffff gggg hhhh
iiii jjjj kkkk llll

In your application, it's not mono-space font, like here:

aaaa bbbb cccc

dddd eeee ffff

gggg hhhh iiii

jjjj kkkk llll

So now you see why it is aligned correctly in your eclipse but failed in your application.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download