The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > JToolBar  [4 examples]

e817. Determining When a Floatable JToolBar Container Changes Orientation

When the orientation of a toolbar is changed, either by the user or programmatically, the toolbar fires a property change event.
    // Create a floatable horizontal toolbar
    JToolBar toolbar = new JToolBar();
    
    // Register for orientation property change events
    toolbar.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        // This method is called whenever the orientation of the toolbar is changed
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            if ("orientation".equals(propName)) {
                // Get the old orientation
                Integer oldValue = (Integer)evt.getOldValue();
    
                // Get the new orientation
                Integer newValue = (Integer)evt.getNewValue();
    
                if (newValue.intValue() == JToolBar.HORIZONTAL) {
                    // toolbar now has horizontal orientation
                } else {
                    // toolbar now has vertical orientation
                }
            }
        }
    });

 Related Examples
e816. Creating a JToolbar Container
e818. Preventing a JToolbar Container from Floating
e819. Highlighting Buttons in a JToolbar Container While Under the Cursor

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.