Results 1 to 2 of 2
  1. #1
    asifzbaig is offline Member
    Join Date
    May 2011
    Rep Power

    Default Please help in prining JPanel

    Hey friends,
    I want to print a JPanel along with its component for which i have my PrintUtilities class as I attached it.

    Here the problem is that whenever i want to print the jPanel i have to passed it through parameter of printComponent(Component) method and it shows me the print dialog.

    What i actually want is to show the printDialog only once in running application for printing setup and after that it directly prints the component whenever i call the printComponent() method.

    Please suggest me what i have to change in my code???

    Please help me...
    Attached Files Attached Files

  2. #2
    asifzbaig is offline Member
    Join Date
    May 2011
    Rep Power


    Here is the same code what i have attached before:

    package Classes;

    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;

    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();
    if (printJob.printDialog())
    try {
    } catch(PrinterException pe) {
    System.out.println("Error printing: " + pe);

    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
    } else {
    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

    public static void disableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);

    public static void enableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);

Similar Threads

  1. Adding a jpanel to a customized Jpanel Class
    By trishtren in forum AWT / Swing
    Replies: 7
    Last Post: 04-05-2011, 07:52 PM
  2. Adding Jpanel ontop of another Jpanel
    By Manfizy in forum AWT / Swing
    Replies: 4
    Last Post: 03-05-2011, 11:34 PM
  3. Placing a new JPanel over a paint overriden JPanel
    By Tanshaydar in forum AWT / Swing
    Replies: 4
    Last Post: 12-08-2010, 07:00 PM
  4. Replies: 1
    Last Post: 11-09-2010, 10:28 AM
  5. .add to a JPanel
    By harrier in forum NetBeans
    Replies: 11
    Last Post: 07-13-2010, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts