FileDocCategorySizeDatePackage
JSeparator.javaAPI DocJava SE 6 API8770Tue Jun 10 00:26:38 BST 2008javax.swing

JSeparator

public class JSeparator extends JComponent implements SwingConstants, Accessible
JSeparator provides a general purpose component for implementing divider lines - most commonly used as a divider between menu items that breaks them up into logical groupings. Instead of using JSeparator directly, you can use the JMenu or JPopupMenu addSeparator method to create and add a separator. JSeparators may also be used elsewhere in a GUI wherever a visual divider is useful.

For more information and examples see How to Use Menus, a section in The Java Tutorial.

Warning: Swing is not thread safe. For more information see Swing's Threading Policy.

Warning: 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 JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

beaninfo
attribute: isContainer false description: A divider between menu items.
version
1.52 08/08/06
author
Georges Saab
author
Jeff Shapiro

Fields Summary
private static final String
uiClassID
private int
orientation
Constructors Summary
public JSeparator()
Creates a new horizontal separator.


          
     
    
        this( HORIZONTAL );
    
public JSeparator(int orientation)
Creates a new separator with the specified horizontal or vertical orientation.

param
orientation an integer specifying SwingConstants.HORIZONTAL or SwingConstants.VERTICAL
exception
IllegalArgumentException if orientation is neither SwingConstants.HORIZONTAL nor SwingConstants.VERTICAL

        checkOrientation( orientation );
	this.orientation = orientation;
	setFocusable(false);
        updateUI();
    
Methods Summary
private voidcheckOrientation(int orientation)

        switch ( orientation )
	{
            case VERTICAL:
            case HORIZONTAL:
                break;
            default:
                throw new IllegalArgumentException( "orientation must be one of: VERTICAL, HORIZONTAL" );
        }
    
public javax.accessibility.AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this JSeparator. For separators, the AccessibleContext takes the form of an AccessibleJSeparator. A new AccessibleJSeparator instance is created if necessary.

return
an AccessibleJSeparator that serves as the AccessibleContext of this JSeparator

        if (accessibleContext == null) {
            accessibleContext = new AccessibleJSeparator();
        }
        return accessibleContext;
    
public intgetOrientation()
Returns the orientation of this separator.

return
The value of the orientation property, one of the following constants defined in SwingConstants: VERTICAL, or HORIZONTAL.
see
SwingConstants
see
#setOrientation

        return this.orientation;
    
public javax.swing.plaf.SeparatorUIgetUI()
Returns the L&F object that renders this component.

return
the SeparatorUI object that renders this component

        return (SeparatorUI)ui;
    
public java.lang.StringgetUIClassID()
Returns the name of the L&F class that renders this component.

return
the string "SeparatorUI"
see
JComponent#getUIClassID
see
UIDefaults#getUI

        return uiClassID;
    
protected java.lang.StringparamString()
Returns a string representation of this JSeparator. 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 null.

return
a string representation of this JSeparator

	String orientationString = (orientation == HORIZONTAL ?
				    "HORIZONTAL" : "VERTICAL");

	return super.paramString() +
	",orientation=" + orientationString;
    
public voidsetOrientation(int orientation)
Sets the orientation of the separator. The default value of this property is HORIZONTAL.

param
orientation either SwingConstants.HORIZONTAL or SwingConstants.VERTICAL
exception
IllegalArgumentException if orientation is neither SwingConstants.HORIZONTAL nor SwingConstants.VERTICAL
see
SwingConstants
see
#getOrientation
beaninfo
bound: true preferred: true enum: HORIZONTAL SwingConstants.HORIZONTAL VERTICAL SwingConstants.VERTICAL attribute: visualUpdate true description: The orientation of the separator.

        if (this.orientation == orientation) {
            return;
        }
        int oldValue = this.orientation;
        checkOrientation( orientation );
        this.orientation = orientation;
        firePropertyChange("orientation", oldValue, orientation);
        revalidate();
	repaint();
    
public voidsetUI(javax.swing.plaf.SeparatorUI ui)
Sets the L&F object that renders this component.

param
ui the SeparatorUI L&F object
see
UIDefaults#getUI
beaninfo
bound: true hidden: true attribute: visualUpdate true description: The UI object that implements the Component's LookAndFeel.

        super.setUI(ui);
    
public voidupdateUI()
Resets the UI property to a value from the current look and feel.

see
JComponent#updateUI

        setUI((SeparatorUI)UIManager.getUI(this));
    
private voidwriteObject(java.io.ObjectOutputStream s)
See readObject and writeObject in JComponent for more information about serialization in Swing.

        s.defaultWriteObject();
        if (getUIClassID().equals(uiClassID)) {
            byte count = JComponent.getWriteObjCounter(this);
            JComponent.setWriteObjCounter(this, --count);
            if (count == 0 && ui != null) {
                ui.installUI(this);
            }
        }