-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
Java HotSpot(TM) Client VM (build 1.5.0_09-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When i get a printable from a JTable the printable object can be printed correctly only one time.
If i try to print the same instance of printable more than one time i get the same number of pages printed, but each page contains the content of the last page.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
using the follow class example press more time on the print button.
The result of the first print is a 2 page print with correct values, pressing the subsequent time on the print button cause the wrongly print of two pages with the content of the second page.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Iexpect that each time i print the same printable object I obtain the same result.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.text.MessageFormat;
import javax.swing.*;
import javax.swing.JTable.PrintMode;
import javax.swing.table.DefaultTableModel;
public class TablePrintBug extends JPanel {
protected JTable table;
protected JButton okButton;
protected JButton cancelButton;
private Printable tablePrintable;
public TablePrintBug(){
init();
DefaultTableModel dtm = new DefaultTableModel(50,8);
this.table.setModel(dtm);
}
private void init() {
table = new JTable();
JScrollPane sp = new JScrollPane(table);
this.add(sp, BorderLayout.CENTER);
okButton = new JButton("print...");
okButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(tablePrintable == null){
tablePrintable = table.getPrintable(PrintMode.NORMAL,
null,
new MessageFormat("Page - {0}"));
}
PrinterJob prnJob = PrinterJob.getPrinterJob();
prnJob.setPrintable(tablePrintable);
if (prnJob.printDialog()) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
prnJob.print();
} catch (PrinterException e1) {
e1.printStackTrace();
}
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
//SwingUtilities.getWindowAncestor((Component)e.getSource()).dispose();
}
});
this.add(okButton,BorderLayout.SOUTH);
}
public Printable getTablePrintable() {
return tablePrintable;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
JFrame f = new JFrame("test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new TablePrintBug());
f.pack();
f.setVisible(true);
}
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
regenerate the printable each time that we want to print the table.
java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
Java HotSpot(TM) Client VM (build 1.5.0_09-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When i get a printable from a JTable the printable object can be printed correctly only one time.
If i try to print the same instance of printable more than one time i get the same number of pages printed, but each page contains the content of the last page.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
using the follow class example press more time on the print button.
The result of the first print is a 2 page print with correct values, pressing the subsequent time on the print button cause the wrongly print of two pages with the content of the second page.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Iexpect that each time i print the same printable object I obtain the same result.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.text.MessageFormat;
import javax.swing.*;
import javax.swing.JTable.PrintMode;
import javax.swing.table.DefaultTableModel;
public class TablePrintBug extends JPanel {
protected JTable table;
protected JButton okButton;
protected JButton cancelButton;
private Printable tablePrintable;
public TablePrintBug(){
init();
DefaultTableModel dtm = new DefaultTableModel(50,8);
this.table.setModel(dtm);
}
private void init() {
table = new JTable();
JScrollPane sp = new JScrollPane(table);
this.add(sp, BorderLayout.CENTER);
okButton = new JButton("print...");
okButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(tablePrintable == null){
tablePrintable = table.getPrintable(PrintMode.NORMAL,
null,
new MessageFormat("Page - {0}"));
}
PrinterJob prnJob = PrinterJob.getPrinterJob();
prnJob.setPrintable(tablePrintable);
if (prnJob.printDialog()) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
prnJob.print();
} catch (PrinterException e1) {
e1.printStackTrace();
}
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
//SwingUtilities.getWindowAncestor((Component)e.getSource()).dispose();
}
});
this.add(okButton,BorderLayout.SOUTH);
}
public Printable getTablePrintable() {
return tablePrintable;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
JFrame f = new JFrame("test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new TablePrintBug());
f.pack();
f.setVisible(true);
}
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
regenerate the printable each time that we want to print the table.