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

BasicToolBarUI has bogus logic that prevents vertical toolbars from docking

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta
    • generic
    • generic



      Name: skT45625 Date: 04/18/2000


      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)


      I can't believe you're testing hasn't picked up on this bug!

      If you create a JToolBar with a vertical orientation that is dockable, you
      won't be able to (reliably) dock it anywhere except the North or South regions.
      Because of the logic error in the code it is _possible_ to get the West/East
      docking to happen but only under extreme conditions, none of which a user will
      understand.

      The bug is in BasicToolBarUI's canDock and getDockingConstraint methods. Both
      of these cache the "dockingSensitivity" variable which determines how close the
      mouse pointer needs to be for the docking to take place. Because the code
      always takes the height of the toolbar this docking distance will always be WAY
      TOO BIG for vertical toolbars(because their height is so much bigger than their
      width).


      Here's a simple testcase that will show the bug. Invoke it with the location
      you want the toolbar(n, s, w or e).

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

      public class docker extends JFrame {

         private JToolBar tbar;

         public static void main(String[] args) {
            new docker((args.length == 0) ? "n" : args[0]);
         }
         public docker(String docked) {

            addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                  System.exit(0);
               }}
            );
            Container c = getContentPane();

            if (docked.equals("n") || docked.equals("s"))
               tbar = new JToolBar(JToolBar.HORIZONTAL);
            else
               tbar = new JToolBar(JToolBar.VERTICAL);

            tbar.add(new JButton("A"));
            tbar.add(new JButton("B"));
            tbar.add(new JButton("C"));

            JButton b = new JButton("Hello");
            c.add(b, BorderLayout.CENTER);
            if (docked.equals("n"))
               c.add(tbar, BorderLayout.NORTH);
            else if (docked.equals("s"))
               c.add(tbar, BorderLayout.SOUTH);
            else if (docked.equals("e"))
               c.add(tbar, BorderLayout.EAST);
            else if (docked.equals("w"))
               c.add(tbar, BorderLayout.WEST);

            pack();
            setBounds(300,300,300,300);
            setVisible(true);
         }
      }
      (Review ID: 103849)
      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: