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

REGRESSION: paint() method not called on JFrame on JDK 1.5

XMLWordPrintable

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


      ADDITIONAL OS VERSION INFORMATION :
      Linux (Mandrake 10.1)
      Windows 2000

      A DESCRIPTION OF THE PROBLEM :
      In JDK 1.5 overriding the paint() method (or paintComponents() for that sake), on JFrame does not work.
      The paint() method is not called when the windows is opened or resized.
      It IS called on restoring after being minimized and when the JFrame window
      is covered by another window and the other window is removed again.



      I *think* the problem appears becaurse the root pane was made opaque in JDK 1.5:

      In Frame.java JDK 1.4:

          protected JRootPane createRootPane() {
              return new JRootPane();
          }

      In Frame.java JDK 1.5:

          protected JRootPane createRootPane() {
              JRootPane rp = new JRootPane();
              // NOTE: this uses setOpaque vs LookAndFeel.installProperty as there
              // is NO reason for the RootPane not to be opaque. For painting to
              // work the contentPane must be opaque, therefor the RootPane can
              // also be opaque.
              rp.setOpaque(true);
              return rp;
          }


      Pleas fix this as many textbooks introducing Java rely on this simple scheme for making simple graphics!

      If it is best for performance that the root pane is opaque, please just state that somewhere but please revert to the JDK 1.4 code.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the includet example code on jdk1.5.0 or jdk1.5.0_01.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A window should pop up showing some custom graphics.
        Program should immediately output 'GrafiskVindue.paint(g)'
      ACTUAL -
      A grey window pops up
        Program prints nothing out

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;

      public class GrafiskVindue extends JFrame
      {
        // Fix to make paint() work in JDK 1.5:
        //protected JRootPane createRootPane() { return new JRootPane(); }

        // Another fix that also makes paint() work in JDK 1.5:
       // { getRootPane().setOpaque(false); }

        public void paint(Graphics g)
        {
          System.out.println("GrafiskVindue.paint(g)"+new java.util.Date());
          super.paint(g); // tegn først GUI-komponenterne
          g.drawLine(0, 0, 50, 50);
          g.fillOval(5, 20, 300, 30);
          g.setColor(Color.green);
          g.drawString("Hej grafiske verden!", 100, 40);
          g.drawLine(0, 0, getWidth(), getHeight());
        }


        public static void main(String[] arg)
        {
          GrafiskVindue vindue = new GrafiskVindue(); // opret vinduet
          vindue.setSize(350, 360); // sæt vinduets størrelse
          vindue.setTitle("GrafiskVindue"); // sæt vinduets titel
          vindue.setVisible(true); // åbn vinduet
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Make the root pane not opaque, for example by putting the code
      { getRootPane().setOpaque(false); }
      somewhere in the class.

      Release Regression From : 1.4.1_06
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-1-07 20:45:15 GMT

            svioletsunw Scott Violet (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: