• 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

printing TABS in strings

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic