Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printing TABS in strings

 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am boggled with this, being new to Java and all. Why is it that the following code will not allow me to print TABS in strings? (i.e., tabs="testing\tone\ttwo\tthree"
Here is my code:
 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should have added that when I run that code (using Java 1.4.1_01 on the Debian operating system), it just prints out that string with all the words crammed together, inside the box. This is wierd.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like the drawString() method doesn't know how to deal with special characters, such as tab. I would suggest you split the String up and use separate drawString() calls with the appropriate x and y arguments to position them where you want.
 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Surely there is some other way to do this? Using separate drawString() methods is rather inefficient, isn't it?
The Deitel & Deitel book just mentioned the "\t" character, but didn't give an example using it. Now I know why, considering that the character was mentioned in Chapter 2, I believe.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you are doing a text-based program, the \t character can be quite useful. It will print as expected if you do something like
 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, but that isn't what I want. I want to do this within an applet. Can it just not be done without sprinkling drawString() methods for every word to be tabbed?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps someone over in The Swing / JFC / AWT Forum has an explanation...
[ January 29, 2003: Message edited by: Dirk Schreckmann ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic