Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems w/ formatted text

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to format some text which is being placed in a JTextArea in a JScrollpane. I am looping though an ArrayList and pulling out the values I need. I have set the String format as follows:

temp = String.format("%1$-20s %2$4s %3$6s%n", name, qty, price);

When the output appears in the JTextArea it looks kind of like the following:

However, if I copy the output from the JTextArea and paste it here, it looks great - exactly like I want it to.

Can anyone please tell me why it does not appear correctly in the JTextArea of my GUI?

Thanks,
Mike

[ EJFH: Added "CODE" tags to preserve formatting. ]
[ October 11, 2006: Message edited by: Ernest Friedman-Hill ]
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't get the question. These two outputs look exactly the same to me.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The font your JTextArea is using must be a [/i]proportional[/i] font, one in which all the characters aren't the same width. Most fonts are proportional fonts. If you set the font to be a fixed-pitch one ("Dialog", "Courier", etc) then things will meet your implicit expectation that all characters should be the same width.
 
Michael Cleary
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops - I should have looked at the post after I entered it. The second output, when pasted into this window (i.e. where you type your post), was lined up perfectly.

In any case, I'll try changing the font as suggested and see how it looks.

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Cleary:
The second output, when pasted into this window (i.e. where you type your post), was lined up perfectly.



That's because in most Web browsers, the textarea widget uses a fixed-pitched font!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic