Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6594157

Subsequent use of Jtable's Printable prints second page twice

    XMLWordPrintable

Details

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: