< prev index next >
src/java.desktop/share/classes/javax/swing/JToolBar.java
Print this page
*** 47,69 ****
import java.io.IOException;
import java.util.Hashtable;
/**
! * <code>JToolBar</code> provides a component that is useful for
! * displaying commonly used <code>Action</code>s or controls.
* For examples and information on using tool bars see
* <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/toolbar.html">How to Use Tool Bars</a>,
* a section in <em>The Java Tutorial</em>.
*
* <p>
* With most look and feels,
* the user can drag out a tool bar into a separate window
! * (unless the <code>floatable</code> property is set to <code>false</code>).
* For drag-out to work correctly, it is recommended that you add
! * <code>JToolBar</code> instances to one of the four "sides" of a
! * container whose layout manager is a <code>BorderLayout</code>,
* and do not add children to any of the other four "sides".
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
* href="package-summary.html#threading">Swing's Threading
--- 47,69 ----
import java.io.IOException;
import java.util.Hashtable;
/**
! * {@code JToolBar} provides a component that is useful for
! * displaying commonly used {@code Action}s or controls.
* For examples and information on using tool bars see
* <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/toolbar.html">How to Use Tool Bars</a>,
* a section in <em>The Java Tutorial</em>.
*
* <p>
* With most look and feels,
* the user can drag out a tool bar into a separate window
! * (unless the {@code floatable} property is set to {@code false}).
* For drag-out to work correctly, it is recommended that you add
! * {@code JToolBar} instances to one of the four "sides" of a
! * container whose layout manager is a {@code BorderLayout},
* and do not add children to any of the other four "sides".
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
* href="package-summary.html#threading">Swing's Threading
*** 73,83 ****
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
! * has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @beaninfo
* attribute: isContainer true
* description: A component which displays commonly used controls or Actions.
--- 73,83 ----
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
! * has been added to the {@code java.beans} package.
* Please see {@link java.beans.XMLEncoder}.
*
* @beaninfo
* attribute: isContainer true
* description: A component which displays commonly used controls or Actions.
*** 100,152 ****
private Insets margin = null;
private boolean floatable = true;
private int orientation = HORIZONTAL;
/**
! * Creates a new tool bar; orientation defaults to <code>HORIZONTAL</code>.
*/
public JToolBar()
{
this( HORIZONTAL );
}
/**
! * Creates a new tool bar with the specified <code>orientation</code>.
! * The <code>orientation</code> must be either <code>HORIZONTAL</code>
! * or <code>VERTICAL</code>.
*
* @param orientation the orientation desired
*/
public JToolBar( int orientation )
{
this(null, orientation);
}
/**
! * Creates a new tool bar with the specified <code>name</code>. The
* name is used as the title of the undocked tool bar. The default
! * orientation is <code>HORIZONTAL</code>.
*
* @param name the name of the tool bar
* @since 1.3
*/
public JToolBar( String name ) {
this(name, HORIZONTAL);
}
/**
! * Creates a new tool bar with a specified <code>name</code> and
! * <code>orientation</code>.
* All other constructors call this constructor.
! * If <code>orientation</code> is an invalid value, an exception will
* be thrown.
*
* @param name the name of the tool bar
* @param orientation the initial orientation -- it must be
! * either <code>HORIZONTAL</code> or <code>VERTICAL</code>
* @exception IllegalArgumentException if orientation is neither
! * <code>HORIZONTAL</code> nor <code>VERTICAL</code>
* @since 1.3
*/
public JToolBar( String name , int orientation) {
setName(name);
checkOrientation( orientation );
--- 100,152 ----
private Insets margin = null;
private boolean floatable = true;
private int orientation = HORIZONTAL;
/**
! * Creates a new tool bar; orientation defaults to {@code HORIZONTAL}.
*/
public JToolBar()
{
this( HORIZONTAL );
}
/**
! * Creates a new tool bar with the specified {@code orientation}.
! * The {@code orientation} must be either {@code HORIZONTAL}
! * or {@code VERTICAL}.
*
* @param orientation the orientation desired
*/
public JToolBar( int orientation )
{
this(null, orientation);
}
/**
! * Creates a new tool bar with the specified {@code name}. The
* name is used as the title of the undocked tool bar. The default
! * orientation is {@code HORIZONTAL}.
*
* @param name the name of the tool bar
* @since 1.3
*/
public JToolBar( String name ) {
this(name, HORIZONTAL);
}
/**
! * Creates a new tool bar with a specified {@code name} and
! * {@code orientation}.
* All other constructors call this constructor.
! * If {@code orientation} is an invalid value, an exception will
* be thrown.
*
* @param name the name of the tool bar
* @param orientation the initial orientation -- it must be
! * either {@code HORIZONTAL} or {@code VERTICAL}
* @exception IllegalArgumentException if orientation is neither
! * {@code HORIZONTAL} nor {@code VERTICAL}
* @since 1.3
*/
public JToolBar( String name , int orientation) {
setName(name);
checkOrientation( orientation );
*** 171,181 ****
}
/**
* Sets the L&F object that renders this component.
*
! * @param ui the <code>ToolBarUI</code> L&F object
* @see UIDefaults#getUI
* @beaninfo
* bound: true
* hidden: true
* attribute: visualUpdate true
--- 171,181 ----
}
/**
* Sets the L&F object that renders this component.
*
! * @param ui the {@code ToolBarUI} L&F object
* @see UIDefaults#getUI
* @beaninfo
* bound: true
* hidden: true
* attribute: visualUpdate true
*** 184,196 ****
public void setUI(ToolBarUI ui) {
super.setUI(ui);
}
/**
! * Notification from the <code>UIFactory</code> that the L&F has changed.
* Called to replace the UI with the latest version from the
! * <code>UIFactory</code>.
*
* @see JComponent#updateUI
*/
public void updateUI() {
setUI((ToolBarUI)UIManager.getUI(this));
--- 184,196 ----
public void setUI(ToolBarUI ui) {
super.setUI(ui);
}
/**
! * Notification from the {@code UIFactory} that the L&F has changed.
* Called to replace the UI with the latest version from the
! * {@code UIFactory}.
*
* @see JComponent#updateUI
*/
public void updateUI() {
setUI((ToolBarUI)UIManager.getUI(this));
*** 219,229 ****
/**
* Returns the index of the specified component.
* (Note: Separators occupy index positions.)
*
! * @param c the <code>Component</code> to find
* @return an integer indicating the component's position,
* where 0 is first
*/
public int getComponentIndex(Component c) {
int ncomponents = this.getComponentCount();
--- 219,229 ----
/**
* Returns the index of the specified component.
* (Note: Separators occupy index positions.)
*
! * @param c the {@code Component} to find
* @return an integer indicating the component's position,
* where 0 is first
*/
public int getComponentIndex(Component c) {
int ncomponents = this.getComponentCount();
*** 238,249 ****
/**
* Returns the component at the specified index.
*
* @param i the component's position, where 0 is first
! * @return the <code>Component</code> at that position,
! * or <code>null</code> for an invalid index
*
*/
public Component getComponentAtIndex(int i) {
int ncomponents = this.getComponentCount();
if ( i >= 0 && i < ncomponents) {
--- 238,249 ----
/**
* Returns the component at the specified index.
*
* @param i the component's position, where 0 is first
! * @return the {@code Component} at that position,
! * or {@code null} for an invalid index
*
*/
public Component getComponentAtIndex(int i) {
int ncomponents = this.getComponentCount();
if ( i >= 0 && i < ncomponents) {
*** 253,271 ****
return null;
}
/**
* Sets the margin between the tool bar's border and
! * its buttons. Setting to <code>null</code> causes the tool bar to
! * use the default margins. The tool bar's default <code>Border</code>
* object uses this value to create the proper margin.
* However, if a non-default border is set on the tool bar,
! * it is that <code>Border</code> object's responsibility to create the
* appropriate margin space (otherwise this property will
* effectively be ignored).
*
! * @param m an <code>Insets</code> object that defines the space
* between the border and the buttons
* @see Insets
* @beaninfo
* description: The margin between the tool bar's border and contents
* bound: true
--- 253,271 ----
return null;
}
/**
* Sets the margin between the tool bar's border and
! * its buttons. Setting to {@code null} causes the tool bar to
! * use the default margins. The tool bar's default {@code Border}
* object uses this value to create the proper margin.
* However, if a non-default border is set on the tool bar,
! * it is that {@code Border} object's responsibility to create the
* appropriate margin space (otherwise this property will
* effectively be ignored).
*
! * @param m an {@code Insets} object that defines the space
* between the border and the buttons
* @see Insets
* @beaninfo
* description: The margin between the tool bar's border and contents
* bound: true
*** 282,292 ****
/**
* Returns the margin between the tool bar's border and
* its buttons.
*
! * @return an <code>Insets</code> object containing the margin values
* @see Insets
*/
public Insets getMargin()
{
if(margin == null) {
--- 282,292 ----
/**
* Returns the margin between the tool bar's border and
* its buttons.
*
! * @return an {@code Insets} object containing the margin values
* @see Insets
*/
public Insets getMargin()
{
if(margin == null) {
*** 295,319 ****
return margin;
}
}
/**
! * Gets the <code>borderPainted</code> property.
*
! * @return the value of the <code>borderPainted</code> property
* @see #setBorderPainted
*/
public boolean isBorderPainted()
{
return paintBorder;
}
/**
! * Sets the <code>borderPainted</code> property, which is
! * <code>true</code> if the border should be painted.
! * The default value for this property is <code>true</code>.
* Some look and feels might not implement painted borders;
* they will ignore this property.
*
* @param b if true, the border is painted
* @see #isBorderPainted
--- 295,319 ----
return margin;
}
}
/**
! * Gets the {@code borderPainted} property.
*
! * @return the value of the {@code borderPainted} property
* @see #setBorderPainted
*/
public boolean isBorderPainted()
{
return paintBorder;
}
/**
! * Sets the {@code borderPainted} property, which is
! * {@code true} if the border should be painted.
! * The default value for this property is {@code true}.
* Some look and feels might not implement painted borders;
* they will ignore this property.
*
* @param b if true, the border is painted
* @see #isBorderPainted
*** 333,346 ****
repaint();
}
}
/**
! * Paints the tool bar's border if the <code>borderPainted</code> property
! * is <code>true</code>.
*
! * @param g the <code>Graphics</code> context in which the painting
* is done
* @see JComponent#paint
* @see JComponent#setBorder
*/
protected void paintBorder(Graphics g)
--- 333,346 ----
repaint();
}
}
/**
! * Paints the tool bar's border if the {@code borderPainted} property
! * is {@code true}.
*
! * @param g the {@code Graphics} context in which the painting
* is done
* @see JComponent#paint
* @see JComponent#setBorder
*/
protected void paintBorder(Graphics g)
*** 350,382 ****
super.paintBorder(g);
}
}
/**
! * Gets the <code>floatable</code> property.
*
! * @return the value of the <code>floatable</code> property
*
* @see #setFloatable
*/
public boolean isFloatable()
{
return floatable;
}
/**
! * Sets the <code>floatable</code> property,
! * which must be <code>true</code> for the user to move the tool bar.
* Typically, a floatable tool bar can be
* dragged into a different position within the same container
* or out into its own window.
! * The default value of this property is <code>true</code>.
* Some look and feels might not implement floatable tool bars;
* they will ignore this property.
*
! * @param b if <code>true</code>, the tool bar can be moved;
! * <code>false</code> otherwise
* @see #isFloatable
* @beaninfo
* description: Can the tool bar be made to float by the user?
* bound: true
* preferred: true
--- 350,382 ----
super.paintBorder(g);
}
}
/**
! * Gets the {@code floatable} property.
*
! * @return the value of the {@code floatable} property
*
* @see #setFloatable
*/
public boolean isFloatable()
{
return floatable;
}
/**
! * Sets the {@code floatable} property,
! * which must be {@code true} for the user to move the tool bar.
* Typically, a floatable tool bar can be
* dragged into a different position within the same container
* or out into its own window.
! * The default value of this property is {@code true}.
* Some look and feels might not implement floatable tool bars;
* they will ignore this property.
*
! * @param b if {@code true}, the tool bar can be moved;
! * {@code false} otherwise
* @see #isFloatable
* @beaninfo
* description: Can the tool bar be made to float by the user?
* bound: true
* preferred: true
*** 394,424 ****
}
}
/**
* Returns the current orientation of the tool bar. The value is either
! * <code>HORIZONTAL</code> or <code>VERTICAL</code>.
*
* @return an integer representing the current orientation -- either
! * <code>HORIZONTAL</code> or <code>VERTICAL</code>
* @see #setOrientation
*/
public int getOrientation()
{
return this.orientation;
}
/**
* Sets the orientation of the tool bar. The orientation must have
! * either the value <code>HORIZONTAL</code> or <code>VERTICAL</code>.
! * If <code>orientation</code> is
* an invalid value, an exception will be thrown.
*
! * @param o the new orientation -- either <code>HORIZONTAL</code> or
! * <code>VERTICAL</code>
* @exception IllegalArgumentException if orientation is neither
! * <code>HORIZONTAL</code> nor <code>VERTICAL</code>
* @see #getOrientation
* @beaninfo
* description: The current orientation of the tool bar
* bound: true
* preferred: true
--- 394,424 ----
}
}
/**
* Returns the current orientation of the tool bar. The value is either
! * {@code HORIZONTAL} or {@code VERTICAL}.
*
* @return an integer representing the current orientation -- either
! * {@code HORIZONTAL} or {@code VERTICAL}
* @see #setOrientation
*/
public int getOrientation()
{
return this.orientation;
}
/**
* Sets the orientation of the tool bar. The orientation must have
! * either the value {@code HORIZONTAL} or {@code VERTICAL}.
! * If {@code orientation} is
* an invalid value, an exception will be thrown.
*
! * @param o the new orientation -- either {@code HORIZONTAL} or
! * {@code VERTICAL}
* @exception IllegalArgumentException if orientation is neither
! * {@code HORIZONTAL} nor {@code VERTICAL}
* @see #getOrientation
* @beaninfo
* description: The current orientation of the tool bar
* bound: true
* preferred: true
*** 500,536 ****
/**
* Appends a separator of a specified size to the end
* of the tool bar.
*
! * @param size the <code>Dimension</code> of the separator
*/
public void addSeparator( Dimension size )
{
JToolBar.Separator s = new JToolBar.Separator( size );
add(s);
}
/**
! * Adds a new <code>JButton</code> which dispatches the action.
*
! * @param a the <code>Action</code> object to add as a new menu item
* @return the new button which dispatches the action
*/
public JButton add(Action a) {
JButton b = createActionComponent(a);
b.setAction(a);
add(b);
return b;
}
/**
! * Factory method which creates the <code>JButton</code> for
! * <code>Action</code>s added to the <code>JToolBar</code>.
! * The default name is empty if a <code>null</code> action is passed.
*
! * @param a the <code>Action</code> for the button to be added
* @return the newly created button
* @see Action
* @since 1.3
*/
protected JButton createActionComponent(Action a) {
--- 500,536 ----
/**
* Appends a separator of a specified size to the end
* of the tool bar.
*
! * @param size the {@code Dimension} of the separator
*/
public void addSeparator( Dimension size )
{
JToolBar.Separator s = new JToolBar.Separator( size );
add(s);
}
/**
! * Adds a new {@code JButton} which dispatches the action.
*
! * @param a the {@code Action} object to add as a new menu item
* @return the new button which dispatches the action
*/
public JButton add(Action a) {
JButton b = createActionComponent(a);
b.setAction(a);
add(b);
return b;
}
/**
! * Factory method which creates the {@code JButton} for
! * {@code Action}s added to the {@code JToolBar}.
! * The default name is empty if a {@code null} action is passed.
*
! * @param a the {@code Action} for the button to be added
* @return the newly created button
* @see Action
* @since 1.3
*/
protected JButton createActionComponent(Action a) {
*** 551,574 ****
b.setVerticalTextPosition(JButton.BOTTOM);
return b;
}
/**
! * Returns a properly configured <code>PropertyChangeListener</code>
! * which updates the control as changes to the <code>Action</code> occur,
! * or <code>null</code> if the default
* property change listener for the control is desired.
*
* @param b a {@code JButton}
* @return {@code null}
*/
protected PropertyChangeListener createActionChangeListener(JButton b) {
return null;
}
/**
! * If a <code>JButton</code> is being added, it is initially
* set to be disabled.
*
* @param comp the component to be enhanced
* @param constraints the constraints to be enforced on the component
* @param index the index of the component
--- 551,574 ----
b.setVerticalTextPosition(JButton.BOTTOM);
return b;
}
/**
! * Returns a properly configured {@code PropertyChangeListener}
! * which updates the control as changes to the {@code Action} occur,
! * or {@code null} if the default
* property change listener for the control is desired.
*
* @param b a {@code JButton}
* @return {@code null}
*/
protected PropertyChangeListener createActionChangeListener(JButton b) {
return null;
}
/**
! * If a {@code JButton} is being added, it is initially
* set to be disabled.
*
* @param comp the component to be enhanced
* @param constraints the constraints to be enforced on the component
* @param index the index of the component
*** 607,617 ****
}
/**
* Creates a new toolbar separator with the specified size.
*
! * @param size the <code>Dimension</code> of the separator
*/
public Separator( Dimension size )
{
super( JSeparator.HORIZONTAL );
setSeparatorSize(size);
--- 607,617 ----
}
/**
* Creates a new toolbar separator with the specified size.
*
! * @param size the {@code Dimension} of the separator
*/
public Separator( Dimension size )
{
super( JSeparator.HORIZONTAL );
setSeparatorSize(size);
*** 630,640 ****
}
/**
* Sets the size of the separator.
*
! * @param size the new <code>Dimension</code> of the separator
*/
public void setSeparatorSize( Dimension size )
{
if (size != null) {
separatorSize = size;
--- 630,640 ----
}
/**
* Sets the size of the separator.
*
! * @param size the new {@code Dimension} of the separator
*/
public void setSeparatorSize( Dimension size )
{
if (size != null) {
separatorSize = size;
*** 645,666 ****
}
/**
* Returns the size of the separator
*
! * @return the <code>Dimension</code> object containing the separator's
* size (This is a reference, NOT a copy!)
*/
public Dimension getSeparatorSize()
{
return separatorSize;
}
/**
* Returns the minimum size for the separator.
*
! * @return the <code>Dimension</code> object containing the separator's
* minimum size
*/
public Dimension getMinimumSize()
{
if (separatorSize != null) {
--- 645,666 ----
}
/**
* Returns the size of the separator
*
! * @return the {@code Dimension} object containing the separator's
* size (This is a reference, NOT a copy!)
*/
public Dimension getSeparatorSize()
{
return separatorSize;
}
/**
* Returns the minimum size for the separator.
*
! * @return the {@code Dimension} object containing the separator's
* minimum size
*/
public Dimension getMinimumSize()
{
if (separatorSize != null) {
*** 671,681 ****
}
/**
* Returns the maximum size for the separator.
*
! * @return the <code>Dimension</code> object containing the separator's
* maximum size
*/
public Dimension getMaximumSize()
{
if (separatorSize != null) {
--- 671,681 ----
}
/**
* Returns the maximum size for the separator.
*
! * @return the {@code Dimension} object containing the separator's
* maximum size
*/
public Dimension getMaximumSize()
{
if (separatorSize != null) {
*** 686,696 ****
}
/**
* Returns the preferred size for the separator.
*
! * @return the <code>Dimension</code> object containing the separator's
* preferred size
*/
public Dimension getPreferredSize()
{
if (separatorSize != null) {
--- 686,696 ----
}
/**
* Returns the preferred size for the separator.
*
! * @return the {@code Dimension} object containing the separator's
* preferred size
*/
public Dimension getPreferredSize()
{
if (separatorSize != null) {
*** 701,712 ****
}
}
/**
! * See <code>readObject</code> and <code>writeObject</code> in
! * <code>JComponent</code> for more
* information about serialization in Swing.
*/
private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
--- 701,712 ----
}
}
/**
! * See {@code readObject} and {@code writeObject} in
! * {@code JComponent} for more
* information about serialization in Swing.
*/
private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
*** 718,735 ****
}
}
/**
! * Returns a string representation of this <code>JToolBar</code>.
* This method
* is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not
! * be <code>null</code>.
*
! * @return a string representation of this <code>JToolBar</code>.
*/
protected String paramString() {
String paintBorderString = (paintBorder ?
"true" : "false");
String marginString = (margin != null ?
--- 718,735 ----
}
}
/**
! * Returns a string representation of this {@code JToolBar}.
* This method
* is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not
! * be {@code null}.
*
! * @return a string representation of this {@code JToolBar}.
*/
protected String paramString() {
String paintBorderString = (paintBorder ?
"true" : "false");
String marginString = (margin != null ?
*** 843,853 ****
return accessibleContext;
}
/**
* This class implements accessibility support for the
! * <code>JToolBar</code> class. It provides an implementation of the
* Java Accessibility API appropriate to toolbar user-interface elements.
*/
protected class AccessibleJToolBar extends AccessibleJComponent {
/**
--- 843,853 ----
return accessibleContext;
}
/**
* This class implements accessibility support for the
! * {@code JToolBar} class. It provides an implementation of the
* Java Accessibility API appropriate to toolbar user-interface elements.
*/
protected class AccessibleJToolBar extends AccessibleJComponent {
/**
< prev index next >