954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to print a nice formatted output in JTextArea?

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?

IcantC
Newbie Poster
15 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

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

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 
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).

IcantC
Newbie Poster
15 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

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

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 
If you need a display formatted in rows/columns like that then JTable may be the best thing


Thanks, I'll try.

IcantC
Newbie Poster
15 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: