2

I think the screenshot is worth a couple of paragraphs

screenshot of the text alignment problem

The best way I can think of doing it is to check for the length of the string and depending give/take \t, but it just seems inelegant. Is there a simpler/better way?

Carlos
  • 5,405
  • 21
  • 68
  • 114

2 Answers2

5

I would use a JTable for this. You can put one in a JScrollPane. This will get you aligned columns automatically. Plus you will get column headers which will aid in understanding what the data means.

MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66
0

If you want to stick with plain text and have an upper bound on the length of fields (which you'd need to guarantee alignment), then you could use printf.

Michael Brewer-Davis
  • 14,018
  • 5
  • 37
  • 49