United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4203039 : JToolBar needs a way to limit docking to a particular orientation

Details
Type:
Bug
Submit Date:
1999-01-14
Status:
Resolved
Updated Date:
2003-08-15
Project Name:
JDK
Resolved Date:
2003-08-15
Component:
client-libs
OS:
generic,windows_xp
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.2.0,1.4.0
Fixed Versions:
5.0 (tiger)

Related Reports
Duplicate:
Relates:
Relates:

Sub Tasks

Description

Name: krT82822			Date: 01/14/99


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

                                    

Comments
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();
    }
}

###@###.### 2003-05-15
                                     
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).
###@###.### 2001-11-14

Changed this
 from rfe to bug, because dragging a toolbar to an
already occupied location makes the component there to disappear.
###@###.### 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.
###@###.### 2003-08-08
                                     
2003-08-08
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b16


                                     
2004-09-01



Hardware and Software, Engineered to Work Together