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

Dragged out JToolbar does not reflect the decoration state of the parent Window

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      at least JDK 6 +

      A DESCRIPTION OF THE PROBLEM :
      JToolBars when dragged out are placed in their own special window. This window does not reflect the decoration state of the top level ancestor of the docked JToolBar. This causes the JToolBar to look awkward if the top level is undecorated. It would be good to:
      1. Analyse the top level and ensure the dragged out JToolBar window is in sync with it in terms of decoration.

      or

      2. Offer the user the ability to configure the JToolBar instance so that it will be decorated or not.

      I think option 1 is currently the best of the two. When would a user want his dragged out JToolBar decorated when the top level of the docked JToolbar is undecorated?

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this test and drag toolbars out:

      public class JToolbar4793741{

          public void testJToolbar(){
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame jf = new JFrame();
              addJToolBar(jf);
              jf.pack();
              jf.setVisible(true);
              Rectangle loc1 = jf.getBounds();

              JFrame.setDefaultLookAndFeelDecorated(false);
              JFrame jf2 = new JFrame();
              addJToolBar(jf2);
              jf2.pack();
              jf2.setLocation(loc1.width, 0);
              jf2.setVisible(true);
              Rectangle loc2 = jf2.getBounds();

              JFrame jf3 = new JFrame();
              jf3.setUndecorated(true);
             
      jf3.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              addJToolBar(jf3);
              jf3.pack();
              jf3.setLocation(loc1.width + loc2.width, 0);
              jf3.setVisible(true);
              Rectangle loc3 = jf3.getBounds();

              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame jf4 = new JFrame();
              jf4.setUndecorated(false);
             
      jf4.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
              addJToolBar(jf4);
              jf4.pack();
              jf4.setLocation(loc1.width + loc2.width +
      loc3.width, 0);
              jf4.setVisible(true);
              Rectangle loc4 = jf4.getBounds();

              JDialog.setDefaultLookAndFeelDecorated(true);
              JDialog jd = new JDialog((Frame)null);
              addJToolBar(jd);
              jd.pack();
              jd.setLocation(0, 200);
              jd.setVisible(true);
              Rectangle dloc1 = jd.getBounds();

              JDialog.setDefaultLookAndFeelDecorated(false);
              JDialog jd2 = new JDialog((Frame)null);
              addJToolBar(jd2);
              jd2.pack();
              jd2.setLocation(dloc1.width, 200);
              jd2.setVisible(true);
              Rectangle dloc2 = jd2.getBounds();

              JDialog jd3 = new JDialog((Frame)null);
              jd3.setUndecorated(true);
             
      jd3.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              addJToolBar(jd3);
              jd3.pack();
              jd3.setLocation(dloc1.width + dloc2.width, 200);
              jd3.setVisible(true);
              Rectangle dloc3 = jd3.getBounds();

              JDialog.setDefaultLookAndFeelDecorated(true);
              JDialog jd4 = new JDialog();
              jd4.setUndecorated(false);
             
      jd4.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
              addJToolBar(jd4);
              jd4.pack();
              jd4.setLocation(dloc1.width + dloc2.width +
      dloc3.width, 200);
              jd4.setVisible(true);
              Rectangle dloc4 = jd4.getBounds();

              final JFrame test2 = new JFrame();
              final JToolBar jtb = addJToolBar(test2);
              JFrame.setDefaultLookAndFeelDecorated(false);
              final JFrame test2b = new JFrame();
              ActionListener al = new ActionListener(){
      public void actionPerformed(ActionEvent ae){
                          System.out.println("SWAP!");
      Object tl = jtb.getTopLevelAncestor();
                          if(tl == test2) test2b.add(jtb);
                          else test2.add(jtb);
                          test2.repaint();
                          test2b.repaint();
                      }

      };
              JButton jb1 = new JButton("Swap");
              jb1.addActionListener(al);
              test2.add(jb1, BorderLayout.SOUTH);
              JButton jb2 = new JButton("Swap");
              jb2.addActionListener(al);
              test2b.add(jb2, BorderLayout.SOUTH);
              test2.pack();
              test2.setLocation(0, 400);
              test2b.setSize(test2.getSize());
              test2.setVisible(true);
              test2b.setLocation(test2.getSize().width,400);
              test2b.setVisible(true);
             


          }

          public static JToolBar addJToolBar(Container con){
              JToolBar jtb = new JToolBar();
              jtb.add(new JButton("one"));
              jtb.add(new JButton("two"));
              jtb.add(new JButton("three"));
              con.add(jtb);
              return jtb;
          }


          public static void main(String ... args){
      Runnable run = new Runnable(){
      public void run(){
      new JToolbar4793741().testJToolbar();
                      }

      };
              SwingUtilities.invokeLater(run);


          }

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      toolbar's decoration should reflect parents decoration
      ACTUAL -
      toolbar is always decorated

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test {

          public void testJToolbar(){
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame jf = new JFrame();
              addJToolBar(jf);
              jf.pack();
              jf.setVisible(true);
              Rectangle loc1 = jf.getBounds();

              JFrame.setDefaultLookAndFeelDecorated(false);
              JFrame jf2 = new JFrame();
              addJToolBar(jf2);
              jf2.pack();
              jf2.setLocation(loc1.width, 0);
              jf2.setVisible(true);
              Rectangle loc2 = jf2.getBounds();

              JFrame jf3 = new JFrame();
              jf3.setUndecorated(true);
             
      jf3.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              addJToolBar(jf3);
              jf3.pack();
              jf3.setLocation(loc1.width + loc2.width, 0);
              jf3.setVisible(true);
              Rectangle loc3 = jf3.getBounds();

              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame jf4 = new JFrame();
              jf4.setUndecorated(false);
             
      jf4.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
              addJToolBar(jf4);
              jf4.pack();
              jf4.setLocation(loc1.width + loc2.width +
      loc3.width, 0);
              jf4.setVisible(true);
              Rectangle loc4 = jf4.getBounds();

              JDialog.setDefaultLookAndFeelDecorated(true);
              JDialog jd = new JDialog((Frame)null);
              addJToolBar(jd);
              jd.pack();
              jd.setLocation(0, 200);
              jd.setVisible(true);
              Rectangle dloc1 = jd.getBounds();

              JDialog.setDefaultLookAndFeelDecorated(false);
              JDialog jd2 = new JDialog((Frame)null);
              addJToolBar(jd2);
              jd2.pack();
              jd2.setLocation(dloc1.width, 200);
              jd2.setVisible(true);
              Rectangle dloc2 = jd2.getBounds();

              JDialog jd3 = new JDialog((Frame)null);
              jd3.setUndecorated(true);
             
      jd3.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              addJToolBar(jd3);
              jd3.pack();
              jd3.setLocation(dloc1.width + dloc2.width, 200);
              jd3.setVisible(true);
              Rectangle dloc3 = jd3.getBounds();

              JDialog.setDefaultLookAndFeelDecorated(true);
              JDialog jd4 = new JDialog();
              jd4.setUndecorated(false);
             
      jd4.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
              addJToolBar(jd4);
              jd4.pack();
              jd4.setLocation(dloc1.width + dloc2.width +
      dloc3.width, 200);
              jd4.setVisible(true);
              Rectangle dloc4 = jd4.getBounds();

              final JFrame test2 = new JFrame();
              final JToolBar jtb = addJToolBar(test2);
              JFrame.setDefaultLookAndFeelDecorated(false);
              final JFrame test2b = new JFrame();
              ActionListener al = new ActionListener(){
      public void actionPerformed(ActionEvent ae){
                          System.out.println("SWAP!");
      Object tl = jtb.getTopLevelAncestor();
                          if(tl == test2) test2b.add(jtb);
                          else test2.add(jtb);
                          test2.repaint();
                          test2b.repaint();
                      }

      };
              JButton jb1 = new JButton("Swap");
              jb1.addActionListener(al);
              test2.add(jb1, BorderLayout.SOUTH);
              JButton jb2 = new JButton("Swap");
              jb2.addActionListener(al);
              test2b.add(jb2, BorderLayout.SOUTH);
              test2.pack();
              test2.setLocation(0, 400);
              test2b.setSize(test2.getSize());
              test2.setVisible(true);
              test2b.setLocation(test2.getSize().width,400);
              test2b.setVisible(true);
             


          }

          public static JToolBar addJToolBar(Container con){
              JToolBar jtb = new JToolBar();
              jtb.add(new JButton("one"));
              jtb.add(new JButton("two"));
              jtb.add(new JButton("three"));
              con.add(jtb);
              return jtb;
          }


          public static void main(String ... args){
      Runnable run = new Runnable(){
      public void run(){
      new Test().testJToolbar();
                      }

      };
              SwingUtilities.invokeLater(run);


          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      add hierarchy listener to JToolBar and undecorate the parent when it is dragged out.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: