how to print data

HiI am trying to printout text area data Please help me how to do this?and also give idea about how to print table data ?
[149 byte] By [bhalke_rakesha] at [2007-10-2 10:39:50]
# 1

Are you talking about printing the text area contents to a console, or to a hardcopy printing device?

Console printing is easy. Your text area should have a getText() method. Given that it should be pretty straightoforward to sent what it returns to System.out.

However, if you mean printing to a hardcopy printer, I haven't done it, but there is the java.awt.print package (in 5.0). I'd start research with the java.awt.print.PrinterJob class. Exactly how the print package is used, and exactly how to print a text area, let alone a table, I can't begin to tell you.

Laszlo_Smitha at 2007-7-13 2:46:03 > top of Java-index,Desktop,Core GUI APIs...
# 2

Here's a quick-and-dirty example of how to get something to print from Java. As you can see, the Prinatable interface defines a print() method. That print() is passed in a Graphics objects. That Graphics object is then used by the object you want to print to print itself to. In this example, I just dummied up a Canvas whos paint(Graphics) method just writes out a string. This same call to paint() from print might work for a Table.

Of course this example is terribly rudimentary, but it does actually print (for me).

import java.awt.print.*;

import java.awt.*;

public class Main

{

public static void main(String[] args)

{

PrintableCanvas printMe = new Main().new PrintableCanvas();

printMe.setSize(500,500);

PrinterJob pj = PrinterJob.getPrinterJob();

pj.setPrintable(printMe);

try

{

pj.print();

}

catch(PrinterException pe)

{

pe.printStackTrace();

}

}

class PrintableCanvas extends Canvas implements Printable

{

public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)

{

paint(graphics);

if(pageIndex == 0)

return PAGE_EXISTS;

else

return NO_SUCH_PAGE;

}

public void paint(Graphics graphics)

{

graphics.drawString("This was printed from Java",200,200);

}

}

}

Laszlo_Smitha at 2007-7-13 2:46:03 > top of Java-index,Desktop,Core GUI APIs...