JIDE Common Layer 2.7.6

com.jidesoft.swing
Class LabeledTextField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jidesoft.swing.LabeledTextField
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class LabeledTextField
extends javax.swing.JPanel

LabeledTextField is a combo component which includes text field and an optional JLabel in the front and another optional AbstractButton at the end.

See Also:
Serialized Form

Nested Class Summary
static interface LabeledTextField.PopupMenuCustomizer
          The PopupMenuCustomizer for the context menu when clicking on the label/icon before the text field.
 
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
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  javax.swing.AbstractButton _button
           
protected  javax.swing.KeyStroke _contextMenuKeyStroke
           
protected  LabeledTextField.PopupMenuCustomizer _customizer
           
protected  javax.swing.JLabel _hintLabel
           
protected  java.lang.String _hintText
           
protected  javax.swing.Icon _icon
           
protected  javax.swing.JLabel _label
           
protected  java.lang.String _labelText
           
protected  javax.swing.JTextField _textField
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
LabeledTextField()
           
LabeledTextField(javax.swing.Icon icon)
           
LabeledTextField(javax.swing.Icon icon, java.lang.String labelText)
           
 
Method Summary
protected  javax.swing.AbstractButton createButton()
          Creates the button that appears after the text field.
protected  JidePopupMenu createContextMenu()
          Creates a context menu.
protected  javax.swing.JLabel createLabel()
          Creates the label that appears before the text field.
protected  javax.swing.JTextField createTextField()
          Creates a text field.
 int getBaseline(int width, int height)
           
 javax.swing.AbstractButton getButton()
          Gets the AbstractButton that appears after text field.
 javax.swing.KeyStroke getContextMenuKeyStroke()
          Gets the keystroke that will bring up the context menu.
 java.lang.String getHintText()
          Gets the hint text when the field is empty and not focused.
 javax.swing.Icon getIcon()
          Gets the icon that appears before the text field.
 javax.swing.JLabel getLabel()
          Gets the JLabel that appears before text field.
 java.lang.String getLabelText()
          Gets the text that appears before the text field.
 LabeledTextField.PopupMenuCustomizer getPopupMenuCustomizer()
          Gets the PopupMenuCustomizer.
 java.lang.String getText()
          Gets the text in this TextField.
 javax.swing.JTextField getTextField()
          Gets the actual text field.
protected  void initComponent()
           
protected  void initLayout(javax.swing.JLabel label, javax.swing.JTextField field, javax.swing.AbstractButton button)
          Setup the layout of the components.
 void setColumns(int columns)
          Sets the number of columns in this TextField, and then invalidate the layout.
 void setContextMenuKeyStroke(javax.swing.KeyStroke contextMenuKeyStroke)
          Changes the keystroke that brings up the context menu which is normally shown when user clicks on the label icon before the text field.
 void setEnabled(boolean enabled)
           
 void setHintText(java.lang.String hintText)
          Sets the hint text.
 void setIcon(javax.swing.Icon icon)
          Sets the icon that appears before the text field.
 void setLabelText(java.lang.String text)
          Sets the text that appears before the text field.
 void setPopupMenuCustomizer(LabeledTextField.PopupMenuCustomizer customizer)
          Sets the PopupMenuCustomizer.
 void setText(java.lang.String text)
          Sets the text in this TextField.
protected  void showContextMenu()
          Shows the context menu.
 void updateUI()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
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, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, 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, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_textField

protected javax.swing.JTextField _textField

_label

protected javax.swing.JLabel _label

_button

protected javax.swing.AbstractButton _button

_labelText

protected java.lang.String _labelText

_icon

protected javax.swing.Icon _icon

_hintText

protected java.lang.String _hintText

_hintLabel

protected javax.swing.JLabel _hintLabel

_customizer

protected LabeledTextField.PopupMenuCustomizer _customizer

_contextMenuKeyStroke

protected javax.swing.KeyStroke _contextMenuKeyStroke
Constructor Detail

LabeledTextField

public LabeledTextField()

LabeledTextField

public LabeledTextField(javax.swing.Icon icon)

LabeledTextField

public LabeledTextField(javax.swing.Icon icon,
                        java.lang.String labelText)
Method Detail

initComponent

protected void initComponent()

showContextMenu

protected void showContextMenu()
Shows the context menu.


initLayout

protected void initLayout(javax.swing.JLabel label,
                          javax.swing.JTextField field,
                          javax.swing.AbstractButton button)
Setup the layout of the components. By default, we used a border layout with label first, field in the center and button last.

Parameters:
label - the label
field - the text field.
button - the button

createTextField

protected javax.swing.JTextField createTextField()
Creates a text field. By default it will return a JTextField with opaque set to false. Subclass can override this method to create their own text field such as JFormattedTextField.

Returns:
a text field.

createContextMenu

protected JidePopupMenu createContextMenu()
Creates a context menu. The context menu will be shown when user clicks on the label.

Returns:
a context menu.

updateUI

public void updateUI()
Overrides:
updateUI in class javax.swing.JPanel

createButton

protected javax.swing.AbstractButton createButton()
Creates the button that appears after the text field. By default it returns null so there is no button. Subclass can override it to create their own button. A typical usage of this is to create a browse button to browse a file or directory.

Returns:
the button.

createLabel

protected javax.swing.JLabel createLabel()
Creates the label that appears before the text field. By default, it only has a search icon.

Returns:
the label.

setLabelText

public void setLabelText(java.lang.String text)
Sets the text that appears before the text field.

Parameters:
text - the text that appears before the text field.

getLabelText

public java.lang.String getLabelText()
Gets the text that appears before the text field.

Returns:
the text that appears before the text field. By default it's null, meaning no text.

setIcon

public void setIcon(javax.swing.Icon icon)
Sets the icon that appears before the text field.

Parameters:
icon - the icon that appears before the text field.

getIcon

public javax.swing.Icon getIcon()
Gets the icon that appears before the text field.

Returns:
the icon that appears before the text field.

getLabel

public javax.swing.JLabel getLabel()
Gets the JLabel that appears before text field.

Returns:
the JLabel that appears before text field.

getButton

public javax.swing.AbstractButton getButton()
Gets the AbstractButton that appears after text field.

Returns:
the AbstractButton that appears after text field.

setColumns

public void setColumns(int columns)
Sets the number of columns in this TextField, and then invalidate the layout.

Parameters:
columns - the number of columns for this text field.

setText

public void setText(java.lang.String text)
Sets the text in this TextField.

Parameters:
text - the new text in this TextField.

getText

public java.lang.String getText()
Gets the text in this TextField.

Returns:
the text in this TextField.

getTextField

public javax.swing.JTextField getTextField()
Gets the actual text field.

Returns:
the actual text field.

setEnabled

public void setEnabled(boolean enabled)
Overrides:
setEnabled in class javax.swing.JComponent

getBaseline

public int getBaseline(int width,
                       int height)
Overrides:
getBaseline in class javax.swing.JComponent

getHintText

public java.lang.String getHintText()
Gets the hint text when the field is empty and not focused.

Returns:
the hint text.

setHintText

public void setHintText(java.lang.String hintText)
Sets the hint text.

Parameters:
hintText - the new hint text.

getPopupMenuCustomizer

public LabeledTextField.PopupMenuCustomizer getPopupMenuCustomizer()
Gets the PopupMenuCustomizer.

Returns:
the PopupMenuCustomizer.

setPopupMenuCustomizer

public void setPopupMenuCustomizer(LabeledTextField.PopupMenuCustomizer customizer)
Sets the PopupMenuCustomizer. PopupMenuCustomizer can be used to do customize the popup menu for the LabeledTextField.

PopupMenuCustomizer has a customize method. The popup menu of this menu will be passed in. You can add/remove/change the menu items in customize method. For example,

 field.setPopupMenuCustomzier(new LabeledTextField.PopupMenuCustomizer() {
     void customize(LabledTextField field, JPopupMenu menu) {
         menu.removeAll();
         menu.add(new JMenuItem("..."));
         menu.add(new JMenuItem("..."));
     }
 }
 
If the menu is never used, the two add methods will never be called thus improve the performance.

Parameters:
customizer - the PopupMenuCustomizer

getContextMenuKeyStroke

public javax.swing.KeyStroke getContextMenuKeyStroke()
Gets the keystroke that will bring up the context menu. If you never set it before, it will return SHIFT-F10 for operating systems other than Mac OS X.

Returns:
the keystroke that will bring up the context menu.

setContextMenuKeyStroke

public void setContextMenuKeyStroke(javax.swing.KeyStroke contextMenuKeyStroke)
Changes the keystroke that brings up the context menu which is normally shown when user clicks on the label icon before the text field.

Parameters:
contextMenuKeyStroke - the new keystroke to bring up the context menu.

JIDE Common Layer 2.7.6