Imprimir um JDialogue

1 resposta
D

Oi pessoal

Alguem sabe uma forma de imprimir um JDialogue??

eu tenho uns labels, textfields, textareas…

Queria saber se pra pra qpegar ele do jeito que ta e mandar pra impressora :slight_smile:

Vlw
Hilton

1 Resposta

H

public class PrintUtilities implements Printable {
private Component componentToBePrinted;

public static void printComponent(Component c) {

new PrintUtilities©.print();

}
public PrintUtilities(Component componentToBePrinted) {

this.componentToBePrinted = componentToBePrinted;

}
public void print() {

// Get a PrinterJob

PrinterJob job = PrinterJob.getPrinterJob();

// Ask user for page format (e.g., portrait/landscape)

PageFormat pf = job.pageDialog(job.defaultPage());

// Specify the Printable is an instance of

// PrintListingPainter; also provide given PageFormat

job.setPrintable(this,pf);

// Print 1 copy

job.setCopies(1);

// Put up the dialog box

if (job.printDialog())

{

// Print the job if the user didn’t cancel printing

try { job.print(); }

catch (Exception e) { /* handle exception */ }

}

}
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {

if (pageIndex > 0) {

return(NO_SUCH_PAGE);

} else {

Graphics2D g2d = (Graphics2D)g;

g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

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.
    */
    public static void disableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager©;
    currentManager.setDoubleBufferingEnabled(false);
    }

/** Re-enables double buffering globally. */

public static void enableDoubleBuffering(Component c) {

RepaintManager currentManager = RepaintManager.currentManager©;

currentManager.setDoubleBufferingEnabled(true);

}

}</blockquote>

Vai imprimir exatamente do jeito que estiver o componente…use essa classe…quando quiser imprimir chame ela assim PrintUtilities.printComponent(seuJDIALOG);

Criado 8 de fevereiro de 2007
Ultima resposta 9 de fev. de 2007
Respostas 1
Participantes 2