problem printing with java
Hi, i am making a text editor which gives the user the option to print. the user enters whatever text into a JTextArea which i then take the string of and pass it to a print class:
publicclass PrintOnePayslipimplements Printable
{
public String printText;
public Font printFont;
public String printTitle;
public PrintOnePayslip(JTextArea textArea, String title)
{
printText = textArea.getText();
printFont = textArea.getFont();
printTitle = title;
// payDet = payD; //recieve pay detais from constructor parameter
// Create a printerJob object
PrinterJob prJob = PrinterJob.getPrinterJob ();
// Set printable class to this class - implementing Printable interface
prJob.setPrintable (this);
// Show print dialog to the user: print (set pages)or cancel
boolean ok = prJob.printDialog();
if (ok)
{
try
{
prJob.print();
}
catch (PrinterException pe)
{
// job did not complete successfully
pe.printStackTrace();
}//end try block
}//end if block
}//end constructor
//print method does the printing / needed to conform to Printable interface
publicint print (Graphics g, PageFormat pageFormat,int page)
{
// don't print to other pages (0th is first page)
if (page > 0)//print called until returns NO_SUCH_PAGE
{
return NO_SUCH_PAGE;
}
//create 2D graphics object - cast graphic to 2D graphic with additional features
Graphics2D g2d=(Graphics2D)g;
// Translate graphic to make corner of printable region origin (0,0)
g2d.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());
g2d.draw (border);
g2d.drawString(printTitle, 100, 80);//draw border
g2d.drawString(printText, 100, 100);
return (PAGE_EXISTS);//the requested page is printed
}//end print method
}//end class PrintOnePayslip
For some reason when the user prints anything with line breaks instead of showing that it shows little boxes like this [].
Does anyone know how to get round this?
thanks

