• Post Reply Bookmark Topic Watch Topic
  • New Topic

string alignment, output to screen  RSS feed

 
david rialto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im trying to align some string output to the screen.
left, center or right alignment.
i've been searching but i have not found anything other than padding the output. i just think thats too specific, like it will only work for this program i'm working on, id like it to be something i could use again.

any ideas?
dr
 
Taariq San
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What might be different about the requirements in another program?
 
david rialto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well you would have to go through and change the padding for whatever new data your trying to represent. If you had something general that would just handle the spacing lets say alignRight(data) for example it would be easy to call and use no matter what.

FYI what im doing is making a paragraph where the user gets to choose the alignment. so what i did as of now, is make the paragraph 100 characters wide.
then for right alignment, i did
int startPosition = 100-currentLine.length(),
and used that value as the starting position for output.
for center alignment do the same but divide startPosition by 2, and start the output there.
 
david rialto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry if that post doesnt make sense i didnt read over it. just typed it and pressed add reply.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find the Formatter class and read about the % tags and the - option.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!