• Post Reply Bookmark Topic Watch Topic
  • New Topic

String formatting in TextArea  RSS feed

 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I have a String that gets printed on the command prompt and also appended into a TextArea. Here the code that formats the String.


When this shows on the command prompt window the semi-colons line up, but in the TextArea they do not.

This is the code that adds the string to the TextArea

 
Tom Reilly
Rancher
Posts: 618
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume when you said that your semicolons don't line up, you meant colons. I also assume you want to see multiple rows and that the columns in each row should line up. What font are you using to display the text in your console and TextArea? Is one font fixed width and the other not?
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Reilly wrote:I assume when you said that your semicolons don't line up, you meant colons. I also assume you want to see multiple rows and that the columns in each row should line up. What font are you using to display the text in your console and TextArea? Is one font fixed width and the other not?


Yes sorry I meant colons. It's supposed to have the username on one side of the colon and the mesasge on the other side with the colons lining. If I did not mention it before it's a Chat program so imagine the client window showing what everyone said. I do not know what the font is for any of them, I did not specify a font so whatever was default font.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(textArea.getFont()).
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:System.out.println(textArea.getFont()).


[family = Dialog, name = Dialog,style = plain, size = 12]
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Courier New is the best known mono spaced font. You can immediately see the difference.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow works great! thanks!
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than use "Courier new" or any such explicit font name you might to better to use the constant Font.MONOSPACED.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oooh, nice! I didn't know that one! (Probably because it was added in Java 6)
 
Paul Clapham
Sheriff
Posts: 22827
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Oooh, nice! I didn't know that one! (Probably because it was added in Java 6)


I thought you were joking, because the ability to use whatever monospaced font the system supports has been around since Day 1. But when I looked in the docs... yes, that String constant has only been around since Java 6. Before that you had to use the hard-coded String constant "Monospaced", if I read the Java 5 docs correctly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!