JDK-4203039 : JToolBar needs a way to limit docking to a particular orientation
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0,1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 1999-01-14
  • Updated: 2003-08-15
  • Resolved: 2003-08-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
5.0 tigerFixed
Related Reports
Duplicate :  
Relates :  
Relates :  

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)

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b16

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

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