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

Metal LAF borders should return copies when asked for BorderInsets.

    Details

      Description

      Name: jk109818 Date: 04/29/2003


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

      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The various border implementations in javax.swing.plaf.metal.MetalBorders should return copies of their border insets on getBorderInsets() calls.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code given.

      EXPECTED BEHAVIOR :
      Insets are changed only for the menu item in question.

      ACTUAL BEHAVIOR:
      All menu items (Foo, Bar, and Baz) show up with a big gap on
      the left, even though the insets are only being changed for menuitem1.
      This bug does not occur for Windows LAFs.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.awt.*;
      import javax.swing.*;

      /**
       * @author Edward Lam
       */
      public class TestFrame extends JFrame {
          
          TestFrame() {
              JMenuBar menubar = new JMenuBar();
              JMenu menu = new JMenu("Foo");
              JMenuItem menuitem1 = new JMenuItem("Bar");
              JMenuItem menuitem2 = new JMenuItem("Baz");
            
              menubar.add(menu);
              menu.add(menuitem1);
              menu.add(menuitem2);
              setJMenuBar(menubar);

              System.out.println(menuitem1.getMargin().left);
              System.out.println(menuitem2.getMargin().left);

              Insets insets = menuitem1.getInsets();
              insets.left += 200;
              menuitem1.setMargin(insets);

              System.out.println(menuitem1.getMargin().left);
              System.out.println(menuitem2.getMargin().left);
          }
          
          public static void main(String []s)
          {
              TestFrame testFrame = new TestFrame();
              testFrame.pack();
              testFrame.setVisible(true);
          }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Create a copy of the Insets object that you receive before modifying it.
      (Review ID: 184526)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              malenkov Sergey Malenkov (Inactive)
              Reporter:
              jkimsunw Jeffrey Kim (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: