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
|