Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4203039
Votes 2
Synopsis JToolBar needs a way to limit docking to a particular orientation
Category java:classes_swing
Reported Against 1.4 , 1.2fcs
Release Fixed 1.5(tiger)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 4172932 , 4239729 , 4664642
Submit Date 14-JAN-1999
Description




When a component like a Combobox or a TextField is added to a 
toolbar it no longer makes sense(IMHO) that it should be docked
in in a vertical orientation. Just take a look at the PC's
WordPad application, which prevents vertically docking of the
toolbar that contains the font combobox. In Visual C++ when a
toolbar containing a combobox is docked vertically, the combobox
component is actually removed temporarily from the toolbar. The
same appears to be true of the  customer  Office family of apps.
I think it would make more sense for the case of toolbars containing
non-button components that the GUI prevent vertical docking instead
of temporarily removing components(but that's my opinion).

The point is that there are probably times when a toolbar should not be
allowed to be docked vertically. Because of this I feel the
JToolBar should provide us with an API to specify the valid
docking orientations(by default it would be ALL). Maybe something
like setDockingOrientation(JToolBar.HORIZONTAL).
(Review ID: 52582)
======================================================================
Work Around
The following example installs a "filter" on the contentpane to only
allow adding toolbars to "North".

Note that it can cause the dragging window outline to have the
wrong orientation sometimes, but that shouldn't be a serious problem.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class ToolBarTest extends JFrame implements ActionListener {
    public ToolBarTest() {
	super("ToolDialog");
	JPanel p = new JPanel() {
	    protected void addImpl(Component comp, Object constraints, int index) {
		if ((getLayout() instanceof BorderLayout)
		    && (comp instanceof JToolBar)
		    && !"North".equals(constraints)) {
 
		    constraints = "North";
		    ((JToolBar)comp).setOrientation(JToolBar.HORIZONTAL);
		}
		super.addImpl(comp, constraints, index);
	    }
	};
	p.setLayout(new BorderLayout());
	p.add(new JScrollPane(new JTree()), "Center");
 
	JToolBar toolbar = new JToolBar();
	JButton button = new JButton("B1");
	button.addActionListener(this);
	toolbar.add(button);
	button = new JButton("B2");
	button.addActionListener(this);
	toolbar.add(button);
	button = new JButton("B3");
	button.addActionListener(this);
	toolbar.add(button);
 
	p.add(toolbar, "North");
 
	setSize(200, 200);
 
	setContentPane(p);
    }
 
    public void actionPerformed(ActionEvent e) {
	System.out.println(e.getActionCommand());
    }
 
    public static void main(String[] args) {
	ToolBarTest t = new ToolBarTest();
	t.show();
    }
}

  xxxxx@xxxxx   2003-05-15
Evaluation
This makes a lot of sense. One way this could be achieved
is for the the toolbar to check if the borderlayout
location is taken before allowing docking there.
Then the app could just place dummy placeholders in
the restricted locations (west and east for example).
  xxxxx@xxxxx   2001-11-14

Changed this
 from rfe to bug, because dragging a toolbar to an
already occupied location makes the component there to disappear.
  xxxxx@xxxxx   2003-07-17


Developers can now add empty components (such as "new JComponent() {}")
to any location where the toolbar shouldn't be allowed to dock. This
makes the need for a new API less pressing.
  xxxxx@xxxxx   2003-08-08
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang