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

REGRESSION: JLayeredPane: moveToFront method does not work with several panel

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 :
      Windows XP Version 2002 service pack 1

      A DESCRIPTION OF THE PROBLEM :
      I used a JLayeredPane containig several panel. Only one panel is visible at the same time. When the visible panel is set to visible, it is moved to front.

        Bug: Only last added panel in the layered pane may be visible. When another panel is moved to front, panel is not displayed.

      See following source code to reproduce the bug.

      It was working fine until jdk1.4.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Start the join source code and click on the button. Panel should switch from Panel 1 to Panel 2

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Clicking on the button may change the visible panel in the JLayeredPane. Each time button is clicked we should see panel 1 -> panel 2 -> panel 1 ...
      ACTUAL -
      Panel 1 is displayed. Button is clicked, no panel is displayed, button is clicked once again , panel 1 is displayed

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No error message

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package demo;

      import java.awt.BorderLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JLayeredPane;
      import javax.swing.JPanel;
      import javax.swing.SwingUtilities;

      public class Bidon {
        public static void main(String[] args) {
          new Bidon().go();
        }

        void go() {
          Runnable run = new Runnable() {
            public void run() {
              JFrame jf = new JFrame();
              JPanel p = new JPanel(new BorderLayout());
              final JLayeredPane pane = new JLayeredPane();
              pane.setLayout(new BorderLayout());
              final JPanel p1 = new JPanel();
              final JPanel p2 = new JPanel();
              pane.add(p2,0);
              pane.add(p1,0);
              
              p2.setVisible(false);
              p1.setVisible(true);
              p1.add(new JLabel("Panel 1"));
              p2.add(new JLabel("Panel 2"));
              pane.moveToFront(p1);

              p.add(pane, BorderLayout.CENTER);
              jf.getContentPane().add(p);
              JButton b = new JButton("Reverse");
              b.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  if (p1.isVisible()) {
                    p1.setVisible(false);
                    p2.setVisible(true);
                    pane.moveToFront(p2);
                  } else {
                    p2.setVisible(false);
                    p1.setVisible(true);
                    pane.moveToFront(p1);
                  }
                }
              });
              p.add(b, BorderLayout.SOUTH);
              jf.pack();

              jf.setVisible(true);
            }
          };
          SwingUtilities.invokeLater(run);
        }
      }
      ---------- END SOURCE ----------

      Release Regression From : 1.4.2
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 10/27/04 21:27 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: