Class JXTitledSeparator
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- org.jdesktop.swingx.JXPanel
-
- org.jdesktop.swingx.JXTitledSeparator
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
,javax.swing.Scrollable
,AlphaPaintable
,BackgroundPaintable
@JavaBean public class JXTitledSeparator extends JXPanel
A simple horizontal separator that contains a title.
JXTitledSeparator allows you to specify the title via the
setTitle(java.lang.String)
method. The title alignment may be specified by using thesetHorizontalAlignment(int)
method, and accepts all the same arguments as theJLabel.setHorizontalAlignment(int)
method.In addition, you may specify an Icon to use with this separator. The icon will appear "leading" the title (on the left in left-to-right languages, on the right in right-to-left languages). To change the position of the title with respect to the icon, call
setHorizontalTextPosition(int)
.The default font and color of the title comes from the
LookAndFeel
, mimicking the font and color of theTitledBorder
Here are a few example code snippets:
//create a plain separator JXTitledSeparator sep = new JXTitledSeparator(); sep.setTitle("Customer Info"); //create a separator with an icon sep = new JXTitledSeparator(); sep.setTitle("Customer Info"); sep.setIcon(new ImageIcon("myimage.png")); //create a separator with an icon to the right of the title, //center justified sep = new JXTitledSeparator(); sep.setTitle("Customer Info"); sep.setIcon(new ImageIcon("myimage.png")); sep.setHorizontalAlignment(SwingConstants.CENTER); sep.setHorizontalTextPosition(SwingConstants.TRAILING);
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.JLabel
label
Implementation detail: the label used to display the titleprivate javax.swing.JSeparator
leftSeparator
Implementation detail: a separator to use on the left of the title if alignment is centered or right justifiedprivate javax.swing.JSeparator
rightSeparator
Implementation detail: a separator to use on the right of the title if alignment is centered or left justified-
Fields inherited from class org.jdesktop.swingx.JXPanel
fakeTransparent
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description JXTitledSeparator()
Creates a new instance ofJXTitledSeparator
.JXTitledSeparator(java.lang.String title)
Creates a new instance ofJXTitledSeparator
with the specified title.JXTitledSeparator(java.lang.String title, int horizontalAlignment)
Creates a new instance ofJXTitledSeparator
with the specified title and horizontal alignment.JXTitledSeparator(java.lang.String title, int horizontalAlignment, javax.swing.Icon icon)
Creates a new instance ofJXTitledSeparator
with the specified title, icon, and horizontal alignment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.ComponentOrientation
getComponentOrientation()
int
getHorizontalAlignment()
Returns the alignment of the title contents along the X axis.int
getHorizontalTextPosition()
Returns the horizontal position of the title's text, relative to the icon.javax.swing.Icon
getIcon()
Returns the graphic image (glyph, icon) that theJXTitledSeparator
displays.java.lang.String
getTitle()
Gets the title.private void
layoutSeparator()
Implementation detail.void
setComponentOrientation(java.awt.ComponentOrientation o)
void
setFont(java.awt.Font font)
void
setForeground(java.awt.Color foreground)
void
setHorizontalAlignment(int alignment)
Sets the alignment of the title along the X axis.void
setHorizontalTextPosition(int position)
Sets the horizontal position of the title's text, relative to the icon.void
setIcon(javax.swing.Icon icon)
Defines the icon this component will display.void
setTitle(java.lang.String title)
Sets the title for the separator.protected void
updateTitle()
Implementation detail.-
Methods inherited from class org.jdesktop.swingx.JXPanel
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, installRepaintManager, isAlpha, isInheritAlpha, isOpaque, isOpaquePatch, isPaintBorderInsets, isPaintingBackground, isPaintingOrigin, isPatch, isTransparentBackground, paint, paintComponent, paintComponentPatch, setAlpha, setBackgroundPainter, setInheritAlpha, setOpaque, setOpaquePatch, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHint, uninstallRepaintManager
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
label
private javax.swing.JLabel label
Implementation detail: the label used to display the title
-
leftSeparator
private javax.swing.JSeparator leftSeparator
Implementation detail: a separator to use on the left of the title if alignment is centered or right justified
-
rightSeparator
private javax.swing.JSeparator rightSeparator
Implementation detail: a separator to use on the right of the title if alignment is centered or left justified
-
-
Constructor Detail
-
JXTitledSeparator
public JXTitledSeparator()
Creates a new instance ofJXTitledSeparator
. The default title is simply an empty string. Default justification isLEADING
, and the default horizontal text position isTRAILING
(title follows icon)
-
JXTitledSeparator
public JXTitledSeparator(java.lang.String title)
Creates a new instance ofJXTitledSeparator
with the specified title. Default horizontal alignment isLEADING
, and the default horizontal text position isTRAILING
(title follows icon)
-
JXTitledSeparator
public JXTitledSeparator(java.lang.String title, int horizontalAlignment)
Creates a new instance ofJXTitledSeparator
with the specified title and horizontal alignment. The default horizontal text position isTRAILING
(title follows icon)
-
JXTitledSeparator
public JXTitledSeparator(java.lang.String title, int horizontalAlignment, javax.swing.Icon icon)
Creates a new instance ofJXTitledSeparator
with the specified title, icon, and horizontal alignment. The default horizontal text position isTRAILING
(title follows icon)
-
-
Method Detail
-
updateTitle
protected void updateTitle()
Implementation detail. Handles updates of title color and font on LAF change. For more details see swingx#451.
-
layoutSeparator
private void layoutSeparator()
Implementation detail. lays out this component, showing/hiding components as necessary. Actually changes the containment (removes and adds components).JXTitledSeparator
is treated as a single component rather than a container.
-
setTitle
public void setTitle(java.lang.String title)
Sets the title for the separator. This may be simple html, or plain text.- Parameters:
title
- the new title. Any string input is acceptable
-
getTitle
public java.lang.String getTitle()
Gets the title.- Returns:
- the title being used for this
JXTitledSeparator
. This will be the raw title text, and so may include html tags etc if they were so specified in #setTitle.
-
setHorizontalAlignment
public void setHorizontalAlignment(int alignment)
Sets the alignment of the title along the X axis. If leading, then the title will lead the separator (in left-to-right languages, the title will be to the left and the separator to the right). If centered, then a separator will be to the left, followed by the title (centered), followed by a separator to the right. Trailing will have the title on the right with a separator to its left, in left-to-right languages.
LEFT and RIGHT always position the text left or right of the separator, respectively, regardless of the language orientation.
- Parameters:
alignment
- One of the following constants defined inSwingConstants
:LEFT
,CENTER
,RIGHT
,LEADING
(the default) orTRAILING
.- Throws:
java.lang.IllegalArgumentException
- if the alignment does not match one of the accepted inputs.- See Also:
SwingConstants
,getHorizontalAlignment()
-
getHorizontalAlignment
public int getHorizontalAlignment()
Returns the alignment of the title contents along the X axis.- Returns:
- The value of the horizontalAlignment property, one of the
following constants defined in
SwingConstants
:LEFT
,CENTER
,RIGHT
,LEADING
orTRAILING
. - See Also:
setHorizontalAlignment(int)
,SwingConstants
-
setHorizontalTextPosition
public void setHorizontalTextPosition(int position)
Sets the horizontal position of the title's text, relative to the icon.- Parameters:
position
- One of the following constants defined inSwingConstants
:LEFT
,CENTER
,RIGHT
,LEADING
, orTRAILING
(the default).- Throws:
java.lang.IllegalArgumentException
- if the position does not match one of the accepted inputs.
-
getHorizontalTextPosition
public int getHorizontalTextPosition()
Returns the horizontal position of the title's text, relative to the icon.- Returns:
- One of the following constants
defined in
SwingConstants
:LEFT
,CENTER
,RIGHT
,LEADING
orTRAILING
. - See Also:
SwingConstants
-
getComponentOrientation
public java.awt.ComponentOrientation getComponentOrientation()
- Overrides:
getComponentOrientation
in classjava.awt.Component
-
setComponentOrientation
public void setComponentOrientation(java.awt.ComponentOrientation o)
- Overrides:
setComponentOrientation
in classjava.awt.Component
-
setIcon
public void setIcon(javax.swing.Icon icon)
Defines the icon this component will display. If the value of icon is null, nothing is displayed.The default value of this property is null.
- See Also:
setHorizontalTextPosition(int)
,getIcon()
-
getIcon
public javax.swing.Icon getIcon()
Returns the graphic image (glyph, icon) that theJXTitledSeparator
displays.- Returns:
- an Icon
- See Also:
setIcon(javax.swing.Icon)
-
setForeground
public void setForeground(java.awt.Color foreground)
- Overrides:
setForeground
in classjavax.swing.JComponent
-
setFont
public void setFont(java.awt.Font font)
- Overrides:
setFont
in classjavax.swing.JComponent
-
-