Results 1 to 6 of 6
- 06-10-2010, 02:34 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 20
- Rep Power
- 0
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).
Can anyone help me, so I can print both panel1 and panel2 with one click?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; } } });
thank you very much
- 06-11-2010, 05:01 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
Emm...
the graphics object should be declared with your both panelsview.panel1.print(graphics);
view.panel2.print(graphics);
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 :)
- 06-11-2010, 07:23 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 20
- Rep Power
- 0
Thank firstly for the answer.
I tried the solution of yours
and it didn´t work. What I get now is 2 blank papers.Java Code:view.panel1.print(view.panel1.getGraphics()); view.panel2.print(view.panel2.getGraphics());
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
:)
- 06-11-2010, 07:27 AM #4
- 06-11-2010, 07:35 PM #5
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
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
- 06-14-2010, 08:45 AM #6
Member
- Join Date
- Apr 2010
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
Using JtabbedPane
By simmi in forum AWT / SwingReplies: 9Last Post: 03-24-2010, 12:24 PM -
print multiple jpanel
By anilkumar_vist in forum New To JavaReplies: 0Last Post: 02-05-2010, 03:28 PM -
Adding a panel to a panel
By rclausing in forum New To JavaReplies: 7Last Post: 02-02-2010, 05:56 AM -
Print the text file and print preview them
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:04 PM -
Help with JTabbedPane
By lenny in forum SWT / JFaceReplies: 1Last Post: 08-07-2007, 06:18 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks