• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

String problem

When I draw a string with the drawString method of the Graphics class, it ignores escape characters such as \n.

For example if I execute the following code:

str="TESTING TEXT: newline:\n tab:\t END";
g.drawString(str, pvalx, pvaly+ascent);

System.out.println cmmand prints out the string in a correct format on the command prompt screen, like

TESTING TEXT: newline:
 tab:    END

but drawString ignores the escape characters and prints out text in a single line like

TESTING TEXT:newline:tab:END

Can anyone please tell me how to overcome this problem so that the string can be drawn  in the correct format?

1 Solution
Yes, you should break your text into separate strings and
put them in place one by one.
It's easy to write code that puts every next line so-many pixels lower.
If you don't like that you should use a (SWING) control that interpretes HTML, but then you should change your string data accordingly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now