JDK-4239729 : Floatable toolbar brokes BorderLayout
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.1
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 1999-05-19
  • Updated: 1999-05-20
  • Resolved: 1999-05-20
Related Reports
Relates :  
Description

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) 
======================================================================

Comments
WORK AROUND Name: vi73552 Date: 05/19/99 No known work-around, yet. Just don't do it. ======================================================================
11-06-2004

EVALUATION Until there is a toolbar container, JToolbar requires its own container with a border layout. georges.saab@Eng 1999-05-20
20-05-1999