This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Escape character \t not reflected in output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Escape character \t not reflected in output" Watch "Escape character \t not reflected in output" New topic
Author

Escape character \t not reflected in output

cathy smith
Greenhorn

Joined: Feb 21, 2003
Posts: 2
Help, I have a simple output line:
JOptionPane.showMessageDialog(null, "sum\t= " + sum + "\nx\t= " + x);
...however, the \t escape character seems to be ignored in my output. if I replace JOptionPane.showMessageDialog to:
System.out.println
the tab is reflected in the command line window.
What can I do to make it work in the first case.
any help appreciated
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I would suggest that you review JLabel. There is no mention (that I can see) that the '\t' like characters will be expanded. You can however use HTML in labels.
I'm guessing here, but maybe you can use java.io.PrintWriter and java.io.StringWriter to do some of the formatting for you. You can then use the resulting formatted string in your message dialog.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
UPDATED:Unfortunately the following does not work !!!
The '\t' is still in the string when it is printed to System.out, a pity....

Here's me just playing around, but it may work for you:

[ February 22, 2003: Message edited by: Barry Gaunt ]
[ February 22, 2003: Message edited by: Barry Gaunt ]
[ February 22, 2003: Message edited by: Barry Gaunt ]
cathy smith
Greenhorn

Joined: Feb 21, 2003
Posts: 2
Thanks for your reply. I'm in the beginning chapters of learning Java, so haven't yet learned how to pass values to JoptionPane.showMessage dialog (or other objects). I'll keep your suggestion in mind when I get to that chapter.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Escape character \t not reflected in output
 
Similar Threads
including jsp file using xsl
A small problem in replaceAll
compile error
question about using boolean to check a condition of an object?
Using currentTimeMillis correctly