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?

Recommended Answers

All 4 Replies

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

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

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

Thanks, I'll try.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.