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).