Really need help in printing JTextArea. Please help me

Hi,
i want to print the content of JTextarea which span more than 1 page.i have tried all suggestion in the forums but still have the same result.
it only print the first page.
Please help me.
attached is the code for printing:
public class PrintUtilities implements Printable {
private Component componentToBePrinted;
public static void printComponent(Component c) {
new PrintUtilities(c).print();
public PrintUtilities(Component componentToBePrinted) {
this.componentToBePrinted = componentToBePrinted;
public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
try {
printJob.print();
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
/* get component width and table height */
Dimension dimension = componentToBePrinted.getSize();
double compWidth      = dimension.width;
double compHeight     = dimension.height;
/* get page width and page height */
double pageWidth      = pageFormat.getImageableWidth();
double pageHeight      = pageFormat.getImageableHeight();
double scale = pageWidth / compWidth;
/* calculate the no. of pages to print */
final int totalNumPages= (int) Math.ceil( ( scale * compHeight ) / pageHeight );
if (pageIndex > totalNumPages) {
return(NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
g2.translate( 0f, 0f );
g2.translate( 0f, -pageIndex * pageHeight );
g2.scale( scale, scale );
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
/** The speed and quality of printing suffers dramatically if
* any of the containers have double buffering turned on.
* So this turns if off globally.
* @see enableDoubleBuffering
public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
/** Re-enables double buffering globally. */
public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
THANKS

Use freely downloadable smart jprint class AtDocumentPrinter from http://www.activetree.com. This package alos allows you to print contents of any kind of JTextComponent such as JTextField, JTextArea, JEditorPane, and JTextPane.
It breaks the text, images and forms into multiple pages by breaking horizontally and vertically. JTable printing is specially interesting.

Similar Messages

Maybe you are looking for

  • Shared Calendar Invites Keep Repeating

    Off the top, this is likely a rare situation, but with my setup, it happens often.  We have three iCloud accounts that regularly invite each other to events through Calendar, however, these calendars are also shared (read-only) to each other.  The sh

  • LDAP authentication not minding user set

    I have a publishing rule for an internal website setup with LDAP authentication setup for two different domains, the domain the TMG 2010 is joined to (domain1) and another external domain (domain2).  I want users from either domain to be able to auth

  • Validation in SAP PI?

    Hello all, I would like to know what kind of validation we should avoid in PI while designing on an Interface? Like if PI need information from SAP system (suppose target) , in that case where should be the validation included? or is it somehing can

  • Sudden change in network settings - can no longer access web sites

    All of a sudden, I am no longer able to access any web sites on my Mac Mini. Everything was working fine and then yesterday I tried to get on-line to look something up and it didn't work. I restarted the computer, checked internet connectivity - whic

  • Superdrive malfunctions on G5, but works fine in new account

    My Pioneer DVD-RW DVR-106D superdrive on my G5 2x2 is having problems reading data DVDs (takes a very long time to load data, sometimes doesn't work at all). Also, DVD burns do not work as well as in the past. I have found that if I create a new acco