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

JLayeredPane does not paint completely covered components

    XMLWordPrintable

Details

    Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When one component (i.e. a layer) in the JLayeredPane completely covers another layer the covered layer is not painted at all. This is probably some kind of optimization in the implementation of JLayeredPane which unfortunately makes semi transparent overlays almost impossible to implement.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create one JPanel of with bound B1.
      2. Create another JPanel with bounds B2 where covers B2 completely.
      3. Make background color in B1 different from B2 and make the background color in B2 semi-transparent.
      4. Add to layered pane of a frame.
      5. Display frame.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It is expected to see two JPanels one covering the other and the bottom layer shining through the top JPanel.
      ACTUAL -
      Only top JPanel is showing.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import java.awt.Color;
      import java.util.Timer;
      import java.util.TimerTask;

      public class OptimizationBug extends JFrame {

          public OptimizationBug() {
              JPanel layer1 = new JPanel();
              layer1.setBounds(35, 35, 100, 100);
              layer1.setBackground(Color.RED);

              final JPanel layer2 = new JPanel();
              layer2.setBounds(-50, -50, 120, 120); // will be able to cover layer1
              layer2.setBackground(new Color(0, 1, 0, 0.5F)); // 50% transparent green

              getLayeredPane().add(layer1, new Integer(1));
              getLayeredPane().add(layer2, new Integer(2));

              setSize(200, 200);

              // Slide layer2 over layer1
              new Timer().schedule(new TimerTask() {
                  public void run() {
                      layer2.setLocation(layer2.getLocation().x + 1, layer2.getLocation().y + 1);
                      repaint();

                  }
              }, 0, 30);
          }

          public static void main(String arg[]) {
              new OptimizationBug().setVisible(true);
          }
      }

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

      Attachments

        Activity

          People

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: