Results 1 to 6 of 6
  1. #1
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default print multiple panel from JTabbedPane

    Hallo,

    I have a problem by printing a multiple panel from a JTabbedPane.
    Say that I have 2 TabbedPanel and I have a print-button at the main panel.
    I can write the code for printing the visible Panel or any of one panel, but what I want is actually with one Print-button, I can print both of the panels on different pages.

    I try to change the code like this, but what I get is 2 print of panel2. (Panel1 is just overwrited by panel2).

    Java Code:
        private class  PrintListener  implements ActionListener
        {
            public void actionPerformed(ActionEvent evt)
            {
                PrinterJob job = PrinterJob.getPrinterJob(); //Get the printer's job list
                PageFormat pageFormat = job.defaultPage();
                job.setPrintable(new Printable()
                { //We print with this class (btnPrintAction, which implements Printable)
                    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
                    {
                        if (pageIndex >= 2)
                        {
                            return Printable.NO_SUCH_PAGE;
                        }
                        else
                        {
                            Graphics2D g2d = (Graphics2D) graphics;
                            g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    
                            Paper paper = new Paper();
                            paper.setSize(585, 832);
                            paper.setImageableArea(0, 0, 585, 832);
                            view.panel1.print(graphics);
                            view.panel2.print(graphics);
                            return Printable.PAGE_EXISTS;
                        }
                    }
            });
    Can anyone help me, so I can print both panel1 and panel2 with one click?

    thank you very much

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    Emm...

    view.panel1.print(graphics);
    view.panel2.print(graphics);
    the graphics object should be declared with your both panels

    something like a

    Java Code:
    view.panel1.print(panel1.getGraphics());
    view.panel2.print(panel2.getGraphics());

    because you need not a default panel graphics but separate ones =)

    But I am not sure because you don't provide the whole piece of code here.
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  3. #3
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default

    Thank firstly for the answer.

    I tried the solution of yours
    Java Code:
    view.panel1.print(view.panel1.getGraphics());
    view.panel2.print(view.panel2.getGraphics());
    and it didnīt work. What I get now is 2 blank papers.

    well I donīt provide the whole code, since I think my question is a general question.
    Basicly my question is, how to print multiple panels on multiple pages.

    any other solutions?

    Thank you again in advance
    :)

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Quote Originally Posted by Webuser View Post
    Emm...



    the graphics object should be declared with your both panels

    something like a

    Java Code:
    view.panel1.print(panel1.getGraphics());
    view.panel2.print(panel2.getGraphics());

    because you need not a default panel graphics but separate ones =)

    But I am not sure because you don't provide the whole piece of code here.
    Wrong. And never use getGraphics() of a Component in client code. That way lies grief.

    db

  5. #5
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I can say wrong too :P without seeing the whole thing

    the author is showing just a piece of code so maybe there should be another decision

  6. #6
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

Similar Threads

  1. Using JtabbedPane
    By simmi in forum AWT / Swing
    Replies: 9
    Last Post: 03-24-2010, 12:24 PM
  2. print multiple jpanel
    By anilkumar_vist in forum New To Java
    Replies: 0
    Last Post: 02-05-2010, 03:28 PM
  3. Adding a panel to a panel
    By rclausing in forum New To Java
    Replies: 7
    Last Post: 02-02-2010, 05:56 AM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. Help with JTabbedPane
    By lenny in forum SWT / JFace
    Replies: 1
    Last Post: 08-07-2007, 06:18 AM

Tags for this Thread

Posting Permissions

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