public final class ExtendedTextField extends PromptedTextField
When the field has focus and its contents are too large to display: a popup
window will appear containing a multi-line text area that shows the contents
of the field. This text area is fully editable and will un-pop when either:
- the focus is lost (see below)
- the contents are deleted so they can all fit in the standard field.
- the user hits Esc, Enter or Tab
To prevent the extended area from automatically hiding when it loses focus:
- Mark an individual component with the "don't hide" constant:
component.putClientProperty(ExtendedTextField.DONT_HIDE_COMPONENT_ON_FOCUS_CHANGE, Boolean.TRUE)
- or mark a whole window by putting the "don't hide" constant in it's rootPane:
window.getJRootPane().putClientProperty(ExtendedTextField.DONT_HIDE_COMPONENT_ON_FOCUS_CHANGE, Boolean.TRUE)
To prevent the extended area from automatically selecting all its text when it gets focus from another component:
- Mark the component that will lose focus with the "don't select text" constant:
component.putClientProperty(ExtendedTextField.DONT_SELECT_TEXT_ON_FOCUS_CHANGE, Boolean.TRUE)
- or mark a whole window by putting the "don't select text" constant in its rootPane:
window.getJRootPane().putClientProperty(ExtendedTextField.DONT_SELECT_TEXT_ON_FOCUS_CHANGE, Boolean.TRUE)
javax.swing.JTextField.AccessibleJTextField
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DONT_HIDE_COMPONENT_ON_FOCUS_CHANGE
Add this constant with Boolean.TRUE to a components client properties to prevent the extended text area from hiding when
it loses focus to the component:
component.putClientProperty(ExtendedTextField.DONT_HIDE_COMPONENT_ON_FOCUS_CHANGE, Boolean.TRUE) or use: window.getJRootPane().putClientProperty(ExtendedTextField.DONT_HIDE_COMPONENT_ON_FOCUS_CHANGE, Boolean.TRUE) to prevent the text area from hiding when a window gets focus |
static java.lang.String |
DONT_SELECT_TEXT_ON_FOCUS_CHANGE
Add this constant with Boolean.TRUE to a components client properties to prevent the extended text area from selecting text when
it gets focused:
component.putClientProperty(ExtendedTextField.DONT_SELECT_TEXT_ON_FOCUS_CHANGE, Boolean.TRUE) or use: window.getJRootPane().putClientProperty(ExtendedTextField.DONT_SELECT_TEXT_ON_FOCUS_CHANGE, Boolean.TRUE) to prevent the text area from getting selected when it gets selected from a window |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
ExtendedTextField() |
ExtendedTextField(boolean allowTabs)
Create a ExtendedTextArea
|
Modifier and Type | Method and Description |
---|---|
void |
addNotify() |
boolean |
canAllowBreaks()
If false line breaks are filtered like in a standard text field
and the default dialog action is called instead (JTextField.NotifyAction)
|
static java.lang.String |
getClipString(java.awt.FontMetrics fm,
java.lang.String string,
int availTextWidth) |
javax.swing.BoundedRangeModel |
getHorizontalVisibility() |
javax.swing.JTextArea |
getLargerTextArea() |
java.awt.Dimension |
getMinimumSize() |
java.awt.Dimension |
getPreferredSize() |
protected int |
getRowHeight() |
protected void |
paintComponent(java.awt.Graphics g) |
protected void |
processFocusEvent(java.awt.event.FocusEvent e) |
void |
removeNotify() |
void |
scrollRectToVisible(java.awt.Rectangle r) |
void |
setAllowBreaks(boolean allowBreaks)
Determines whether the control allows inputing of line breaks ('\n', enter)
like a text field (no - they are filtered and the default dialog action
can be called instead) or like a text area (yes).
|
void |
setBackground(java.awt.Color color) |
void |
setDocument(javax.swing.text.Document doc) |
void |
setFont(java.awt.Font font) |
void |
setForeground(java.awt.Color color) |
void |
setLargerAreaVisible(boolean visible) |
void |
setScrollOffset(int scrollOffset) |
void |
setText(java.lang.String text) |
getBaseDocument, getPrompt, getPromptForeground, isPromptVisible, setPrompt, setPromptForeground
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, setAction, setActionCommand, setColumns, setHorizontalAlignment
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write
addAncestorListener, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
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
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, 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, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, 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, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final java.lang.String DONT_HIDE_COMPONENT_ON_FOCUS_CHANGE
component.putClientProperty(ExtendedTextField.DONT_HIDE_COMPONENT_ON_FOCUS_CHANGE, Boolean.TRUE)
window.getJRootPane().putClientProperty(ExtendedTextField.DONT_HIDE_COMPONENT_ON_FOCUS_CHANGE, Boolean.TRUE)
public static final java.lang.String DONT_SELECT_TEXT_ON_FOCUS_CHANGE
component.putClientProperty(ExtendedTextField.DONT_SELECT_TEXT_ON_FOCUS_CHANGE, Boolean.TRUE)
window.getJRootPane().putClientProperty(ExtendedTextField.DONT_SELECT_TEXT_ON_FOCUS_CHANGE, Boolean.TRUE)
public ExtendedTextField()
public ExtendedTextField(boolean allowTabs)
allowTabs
- If true tab will insert a tab ('\t') into the document and
ctrl-tab will be required to move focus. If false tab act as focus
traversal key (depending on look and feel).public void addNotify()
addNotify
in class javax.swing.JComponent
public void removeNotify()
removeNotify
in class javax.swing.text.JTextComponent
protected void processFocusEvent(java.awt.event.FocusEvent e)
processFocusEvent
in class java.awt.Component
public void setDocument(javax.swing.text.Document doc)
setDocument
in class javax.swing.JTextField
public void setLargerAreaVisible(boolean visible)
public void setForeground(java.awt.Color color)
setForeground
in class javax.swing.JComponent
public void setBackground(java.awt.Color color)
setBackground
in class javax.swing.JComponent
public void setFont(java.awt.Font font)
setFont
in class javax.swing.JTextField
public void setText(java.lang.String text)
setText
in class javax.swing.text.JTextComponent
public javax.swing.JTextArea getLargerTextArea()
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class javax.swing.JTextField
public java.awt.Dimension getMinimumSize()
getMinimumSize
in class javax.swing.JComponent
protected int getRowHeight()
public javax.swing.BoundedRangeModel getHorizontalVisibility()
getHorizontalVisibility
in class javax.swing.JTextField
public void setScrollOffset(int scrollOffset)
setScrollOffset
in class javax.swing.JTextField
public void scrollRectToVisible(java.awt.Rectangle r)
scrollRectToVisible
in class javax.swing.JTextField
public void setAllowBreaks(boolean allowBreaks)
allowBreaks
- public boolean canAllowBreaks()
protected void paintComponent(java.awt.Graphics g)
paintComponent
in class PromptedTextField
public static java.lang.String getClipString(java.awt.FontMetrics fm, java.lang.String string, int availTextWidth)