0

i've created a jframe with a jpanel with certain things as you can see in the attachment (page1.java)
..............can anyone tell how to print that jpanel(not the whole jframe) and all its contents ........

Edited by Jessurider: n/a

Attachments
4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by NormR1
0

I'm not going to download your zip and look through it entirely. please post your relevant code and be a bit more specific as to what you want..
do you want the JPanel to be printed, or the contents of the JPanel?

0

ya i want the JPanel and the contents of the JPanel to be printed automatically........

Edited by Jessurider: n/a

0

What do you mean by "printing"?
Do you want a copy of the GUI component and contents written/printed to paper?

0

contents of the jpanel to be printed on to a paper through my printer............

Edited by Jessurider: n/a

1

The trick is to get the graphics object for the printing output and then call the components paintComponent method with that object. It will draw itself on the graphics context.

Here's a sample print out to a .PS file using the following:

JFrame frameToPrint;

    public int print(Graphics g, PageFormat pf, int page) throws
                                                        PrinterException {

        if (page > 0) {
            return NO_SUCH_PAGE;
        }

        Graphics2D g2d = (Graphics2D)g;
        g2d.translate(pf.getImageableX(), pf.getImageableY());

        /* Now print the window and its visible contents */
        frameToPrint.printAll(g);

        return PAGE_EXISTS;
    }

Edited by NormR1: n/a

Attachments SamplePrint.png 7.79 KB
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.