Package com.jidesoft.swing
Class LabeledTextField
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.jidesoft.swing.LabeledTextField
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe PopupMenuCustomizer for the context menu when clicking on the label/icon before the text field.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AbstractButtonprotected KeyStrokeprotected LabeledTextField.PopupMenuCustomizerprotected JLabelprotected Stringprotected Iconprotected JLabelprotected Stringprotected booleanprotected JTextFieldFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected PointCalculates the locatioin of the context menu.protected AbstractButtonCreates the button that appears after the text field.protected JidePopupMenuCreates a context menu.protected JLabelCreates the label that appears before the text field.protected JTextFieldCreates a text field.protected voidcustomizePopupMenu(JPopupMenu menu) Customizes the popup menu.intgetBaseline(int width, int height) Gets the AbstractButton that appears after text field.Gets the keystroke that will bring up the context menu.Gets the hint text when the field is empty and not focused.getIcon()Gets the icon that appears before the text field.getLabel()Gets the JLabel that appears before text field.Gets the text that appears before the text field.Gets the PopupMenuCustomizer.getText()Gets the text in this TextField.Gets the actual text field.protected voidprotected voidinitLayout(JLabel label, JTextField field, AbstractButton button) Setup the layout of the components.booleanChecks if the hint text will still be shown when the text field has focus.voidsetColumns(int columns) Sets the number of columns in this TextField, and then invalidate the layout.voidsetContextMenuKeyStroke(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.voidsetEnabled(boolean enabled) voidsetHintText(String hintText) Sets the hint text.voidSets the icon that appears before the text field.voidsetLabelText(String text) Sets the text that appears before the text field.voidSets the PopupMenuCustomizer.voidsetShowHintTextWhenFocused(boolean showHintTextWhenFocused) Sets the flag if the hint text will still be shown when the text field has focus.voidSets the text in this TextField.protected voidShows the context menu.voidupdateUI()Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUIMethods 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, updateMethods 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, validateTreeMethods 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, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
_textField
-
_label
-
_button
-
_labelText
-
_icon
-
_hintText
-
_showHintTextWhenFocused
protected boolean _showHintTextWhenFocused -
_hintLabel
-
_customizer
-
_contextMenuKeyStroke
-
-
Constructor Details
-
LabeledTextField
public LabeledTextField() -
LabeledTextField
-
LabeledTextField
-
-
Method Details
-
initComponent
protected void initComponent() -
showContextMenu
protected void showContextMenu()Shows the context menu. -
calculateContextMenuLocation
Calculates the locatioin of the context menu.- Returns:
- the upper-left corner location.
- Since:
- 3.4.2
-
customizePopupMenu
Customizes the popup menu.- Parameters:
menu- the menu to customize- Since:
- 3.4.1
-
initLayout
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 labelfield- the text field.button- the button
-
isShowHintTextWhenFocused
public boolean isShowHintTextWhenFocused()Checks if the hint text will still be shown when the text field has focus. By default, the hint text is only shown when the text field doesn't have focus.- Returns:
- true or false.
- Since:
- 3.3.6
-
setShowHintTextWhenFocused
public void setShowHintTextWhenFocused(boolean showHintTextWhenFocused) Sets the flag if the hint text will still be shown when the text field has focus. By default, the hint text is only shown when the text field doesn't have focus. If you set it to true, the hint text will always be shown regardless if the text field has focus.- Parameters:
showHintTextWhenFocused- true or false.- Since:
- 3.3.6
-
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
Creates a context menu. The context menu will be shown when user clicks on the label.- Returns:
- a context menu.
-
updateUI
public void updateUI() -
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
Creates the label that appears before the text field. By default, it only has a search icon.- Returns:
- the label.
-
setLabelText
Sets the text that appears before the text field.- Parameters:
text- the text that appears before the text field.
-
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
Sets the icon that appears before the text field.- Parameters:
icon- the icon that appears before the text field.
-
getIcon
Gets the icon that appears before the text field.- Returns:
- the icon that appears before the text field.
-
getLabel
Gets the JLabel that appears before text field.- Returns:
- the JLabel that appears before text field.
-
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
Sets the text in this TextField.- Parameters:
text- the new text in this TextField.
-
getText
Gets the text in this TextField.- Returns:
- the text in this TextField.
-
getTextField
Gets the actual text field.- Returns:
- the actual text field.
-
setEnabled
public void setEnabled(boolean enabled) - Overrides:
setEnabledin classJComponent
-
getBaseline
public int getBaseline(int width, int height) - Overrides:
getBaselinein classJComponent
-
getHintText
Gets the hint text when the field is empty and not focused.- Returns:
- the hint text.
-
setHintText
Sets the hint text.- Parameters:
hintText- the new hint text.
-
getPopupMenuCustomizer
Gets the PopupMenuCustomizer.- Returns:
- the PopupMenuCustomizer.
-
setPopupMenuCustomizer
Sets the PopupMenuCustomizer. PopupMenuCustomizer can be used to do customize the popup menu for theLabeledTextField. 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,If the menu is never used, the two add methods will never be called thus improve the performance.field.setPopupMenuCustomizer(new LabeledTextField.PopupMenuCustomizer() { void customize(LabeledTextField field, JPopupMenu menu) { menu.removeAll(); menu.add(new JMenuItem("...")); menu.add(new JMenuItem("...")); } }- Parameters:
customizer- the PopupMenuCustomizer
-
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
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.
-