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

JProgessBar doesn't show if printed on paper with PrintJob (1.1 Graphics API)

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05
      Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP
      Windows 2000

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      It happens with different machines, no specific hardware.

      A DESCRIPTION OF THE PROBLEM :
      I had a JPanel containing various elements (JButtons, JComboBoxes, JLabel, JTextArea and finally JProgressBar) for some statistics.

      I had to print this frame on paper, so I created a PrintJob, I printed (print() method) on it the JPanel and then I ended the PrintJob to make the printer draw it on paper.

      Everything was printed fine except for the JProgressBar, that was missing (obviously it contained a non-zero value, but anyway I set the setStringPainted() to true, and I also tried to use the setOpaque(true) on the JProgressBar).

      NOTE: the JProgressBar was correctly displayed.

      I tried also creating a separate application that only shows a JProgressBar filled to a random value, and then print it, but nothing was shown on the paper (see code attached).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JPanel and put a JProgressBar in it.
      Create a PrintJob and print on it the JPanel.
      End the PrintJob to make the printer draw the JPanel.
      The JProgressBar is missing.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected to see the JProgressBar printed.
      ACTUAL -
      The JProgressBar wasn't printed at all.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No error mesage.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.BorderLayout;
      import java.awt.PrintJob;
      import java.awt.Toolkit;
      import java.util.Properties;

      public class PrintingTest extends JFrame
      {
      static JFrame TestFrame;
      static JPanel MPanel;
      static JProgressBar PBar;

      public PrintingTest()
      {
      super();
      MPanel = new JPanel(new BorderLayout());
      PBar = new JProgressBar();
      PBar.setOpaque(true);
      PBar.setStringPainted(true);
      PBar.setValue(50);
      MPanel.add("Center",PBar);
      this.setContentPane(MPanel);
      this.setSize(200,50);
      this.setVisible(true);
      PrintJob Pj = Toolkit.getDefaultToolkit().getPrintJob(this,"Stampa statistiche",new Properties());
      this.getContentPane().printAll(Pj.getGraphics());
      Pj.end();
      }

      public static void main(String Args[])
      {
      TestFrame = new PrintingTest();
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Creating a new ProgressBar on my own.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: