• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printinting problem in Swing (not taking new line)  RSS feed

anoopkumarhss kumar
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some text written in my Swing Application whcih needs to be
displayed in the JTextArea. The text is say
The displayed text is perfectly fine i.e "def" is in new line after "abc".

I have to implement the "print" functionality for this text in my Swing application.

The text when represented as string would be of kind "abc\rdef".
Now when I pass this string to drawString() API of Graphics class
the print it out on paper, the printout I receive is on single line
like abcdef.

Where did the carriage return go? How to make sure that my printout
has "def" printed in new line after "abc".

The overridden print() method in MyPrintable class is as follows:

public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {if (pageIndex >= 1) {
return Printable.NO_SUCH_PAGE;
g.setFont(new Font("Arial", Font.PLAIN, 11));
g.drawString(stringToPrint, 100, 100);
return Printable.PAGE_EXISTS;
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!