Hello, forum.
My question is: how can I format my output when outputting in JTextArea.
I want to have the same functionality as System.out.format has (custom spaces between values).
Maybe it is possible to print PrintSream objects in JTextArea?
I am currently using append(String s) method but I am not satisfied with the results since this only gives me an option to output String with no formatting options.
Any ideas?

6 Years
Discussion Span
Last Post by IcantC

Use a JTextPane instead of a JTextArea. Same functionality plus formatted text. API JavaDoc is in the usual places.

Maybe you could point an exact method that does the spacing, because what I can see from examples is only formatting either font color or layout. I will specify my question.

What I have is this:

1. Short name, short number 1.11
2. A little bit longer name, longer number 22.22
3. Very large name and a little longer number after 333.33
4. Very Very super extra large name with even longer number after 4444.44

And what I want is that all the numbers would be aligned in a column .Text should have specified amount of space in each row ( I couldn't demonstrate cause this editor would delete all the spaces I add).


If you need a display formatted in rows/columns like that then JTable may be the best thing

Thanks, I'll try.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.