Elltz Elltz - 1 month ago 11
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

EDIT

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

enter image description here

Answer

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.

Comments