How to align text appended to a JScrollPane
I think the screenshot is worth a couple of paragraphs
The best way I can think of doing it is to check for the length of the string an开发者_StackOverflowd depending give/take \t
, but it just seems inelegant. Is there a simpler/better way?
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.
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.
精彩评论