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

Metal ToolBar Border incorrectly sizes the MetalBumps used for the grip

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.4.2
    • client-libs
    • beta
    • x86
    • windows_2000

      Name: gm110360 Date: 04/21/2004


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

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      The standard JToolBar border contains code to paint the MetalBumps gripper so that the toolbar can be docked/undocked from a borderlayout. The code that paints the border is incorrectly sizing the MetalBumps image, it should be using the passed in border width and height but it is in fact using the width and height of the component (JToolBar). This causes a problem when changing the JToolBar border to be a compound border, as the MetalBumps will draw over the outer border.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      code snippet:

      JToolBar toolBar = new JToolBar();
      toolBar.setFloatable(true);
      toolBar.setRollover(true);
      toolBar.setBorder(new CompoundBorder(new EmptyBorder(10,10,10,10),toolBar.getBorder()));

      if you create the toolbar using the above code, the MetalBumps will draw over empty border.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected the MetalBumps grip part of the inner border to be constrained to inside the Empty Border.
      ACTUAL -
      The top left of the MetalBumps border is drawn in the correct location. The bottom right of the painted MetalBUmps is 2 pixels shy of the bottom of the component (JToolBar) when it should be 2 pixels shy of the empty border component

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Color;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JToolBar;
      import javax.swing.border.CompoundBorder;
      import javax.swing.border.EmptyBorder;

      public class ToolBarBugDemo
      {
      public ToolBarBugDemo()
      {
      super();
      }

      public static void main(String [] args)
      {
      JFrame f = new JFrame();
      f.getContentPane().setLayout(new BorderLayout());
      f.getContentPane().setBackground(Color.blue);
      JToolBar toolBar = new JToolBar();
      toolBar.setFloatable(true);
      toolBar.setRollover(true);
      toolBar.setBorder(new CompoundBorder(new EmptyBorder(10,10,10,10),toolBar.getBorder()));
      toolBar.add(new JButton("testa"));
      toolBar.add(new JButton("testb"));
      toolBar.add(new JButton("testc"));
      toolBar.add(new JButton("testd"));
      f.getContentPane().add(toolBar,BorderLayout.NORTH);
      f.setSize(400,200);
      f.setVisible(true);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Not a workaround as such, but a solution:

      The current paintBorder() code from the MetalBorders.TollBarBorder class in the swing set is as follows:

      public void paintBorder( Component c, Graphics g, int x, int y, int w, int h )
      {
          g.translate( x, y );
          if ( ((JToolBar) c).isFloatable() )
          {
              if ( ((JToolBar) c).getOrientation() == HORIZONTAL )
      {
      bumps.setBumpArea( 10, c.getSize().height - 4 );
                  if( MetalUtils.isLeftToRight(c) ) {
                       bumps.paintIcon( c, g, 2, 2 );
                  } else {
                       bumps.paintIcon( c, g, c.getBounds().width-12, 2 );
                  }
      }
      else // vertical
      {
      bumps.setBumpArea( c.getSize().width - 4, 10 );
      bumps.paintIcon( c, g, 2, 2 );
      }
          }

          g.translate( -x, -y );
      }


      it is incorrectly using c.getSize().width and c.getSize().height to determine the bounds for the bumps. It should be using the passed in w and h variables to determine this.

      a workaround for this requires that you copy the MetalBumps code from the same package, as it is pacakge protected and the protected member cannot be accessed from a subclass.
      (Incident Review ID: 214804)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: