I have a jtable with which I display my database. I would like to preview the pages before printing, and in portrait mode all is correct :

dOM93.png

but when I change the mode to landscape, there is a loss of data. It does not display all the rows of the table. It only takes the last page and copies it to the other pages.

rI7XR.png

[CODE]

protected void getThePreviewPages()
{
m_wPage = (int)(pp_pf.getWidth());
m_hPage = (int)(pp_pf.getHeight());
int scale = getDisplayScale();
width = (int)Math.ceil(m_wPage*scale/100);
height = (int)Math.ceil(m_hPage*scale/100);

int pageIndex = 0;
try {
while (true) {
BufferedImage img = new BufferedImage(m_wPage, m_hPage,
BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, m_wPage, m_hPage);
if (bScallToFitOnePage) {
m_target.print(g, pp_pf, -1);
PagePreview pp = new PagePreview(width, height, img);
m_preview.add(pp);
break;
} else
if (m_target.print(g, pp_pf, pageIndex) != Printable.PAGE_EXISTS)
break;
PagePreview pp = new PagePreview(width, height, img);
m_preview.add(pp);
pageIndex++;
}
} catch (OutOfMemoryError om) {
JOptionPane.showMessageDialog(this,
"image is too big that run out of memory.", "Print Preview",
JOptionPane.INFORMATION_MESSAGE);
}
catch (PrinterException e) {
e.printStackTrace();
System.err.println("Printing error: "+e.toString());
}
}

protected void previewThePages(int orientation)
{
if (displayArea != null) displayArea.setVisible(false);

m_preview = new PreviewContainer();

getThePreviewPages();
JPanel panel = new JPanel();
panel.add(m_preview);
JPanel panel1 = new JPanel();
panel1.add(panel);

displayArea = new JScrollPane(panel1);
getContentPane().add(displayArea, BorderLayout.CENTER);
setLocationRelativeTo(null);
setResizable(true);
setExtendedState(this.MAXIMIZED_BOTH);
setVisible(true);
System.gc();
}