-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.2.1
-
generic
-
generic
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)
======================================================================
- relates to
-
JDK-4203039 JToolBar needs a way to limit docking to a particular orientation
-
- Resolved
-