I'm working on a text editor and my next goal is to print the written text on a printer (not sysout).
I tried it many times and it worked but the line breaks got ignored.
Graphics pg = prjob.getGraphics();
pg.setFont(textFont);
pg.drawString(window.getText(), iPosX, iPosY);
pg.dispose();
I created a new graphics and set the font.
Then I took the text which was written into my editor window.
iPosX
& iPosY
are the measurement of the paper.
How can I print the whole String considering the line breaks?
Apparently,
drawString()
method does not handle line breaks. You can solve this by splitting the String on line breaks and printing each line separately on a new line. You can create a custom method to use like this one:Hope it helps!