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

Floatable toolbar brokes BorderLayout

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.1
    • client-libs



      Name: vi73552 Date: 05/19/99


      Moving a toolbar to an area that already has a component causes the layout (BorderLayout) to behave incorrectly. The problem is demonstrated by the following code.

      Simply drag the toolbar to the SOUTH and deposit it there. It will go behind the JTextField. When you move it out of the area, the layout no longer functions correctly. Resizing the window no longer causes the JTextField to be anchored in the SOUTHern region of the layout.

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

      class TBButton extends JButton
      {
         public TBButton(int nActionID, String sImage, String sTip)
         {
             super(new ImageIcon(sImage));
             setMargin(new Insets(1,1,1,1));
             setToolTipText(sTip);
         }
         public void requestFocus() {} // toolbar buttons can't get focus
         public float getAlignmentY() { return 0.5f; }
      };

      class Toolbar extends JToolBar
      {
        public Toolbar()
        {
           super();
           TBButton button = new TBButton(1, "file_open.gif","Load Data");
           add(button);

           button = new TBButton(2, "file_save.gif","Save Data");
           add(button);

          add(Box.createHorizontalStrut(5));
          add(Box.createHorizontalGlue());
        }
      };

      public class Docking extends JFrame
      {
         public Docking()
         {
            Toolbar tb = new Toolbar();
            tb.setFloatable(true);
            getContentPane().add(tb,BorderLayout.NORTH);
            getContentPane().add(new JTextField("Just try to dock here! I'll screw your layout!"),BorderLayout.SOUTH);
            addWindowListener(new Closer());
         }
         public static void main(String [] args)
         {
            Docking d = new Docking();
            d.setSize(300,300);
            d.setVisible(true);
         }
         class Closer extends WindowAdapter
         {
            public void windowClosing(WindowEvent ev)
            {
               System.exit(0);
            }
         };
      };
      (Review ID: 83274)
      ======================================================================

            gsaab Georges Saab
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: