java.lang.Object | +--java.awt.Component | +--LWTextComponent
Implements a very simple lightweight text editing component. It lets the user edit a single line of text using the keyboard. The only special character that it knows about is backspace; all other characters are added to the text. Selections are not supported, so there's only a simple caret indicating the insertion point. The component also displays a component name above the editable text line, and draws a black frame whose thickness indicates whether the component has the focus.
The component can be initialized to enable or disable input through input methods. Other than that, it doesn't do anything to support input methods, so input method interaction (if any) will occur in a separate composition window. However, the component is designed to be easily extended with full input method support. It distinguishes between "displayed text" and "committed text" - here, they're the same, but in a subclass that supports on-the-spot input, the displayed text would be the combination of committed text and composed text. The component also uses TextLayout to draw the text, so it can be easily extended to handle input method highlights.
LWTextComponent (String name,
boolean enableInputMethods)
void
focusGained (FocusEvent event)
Rectangle
getCaretRectangle (TextHitInfo caret)
AttributedCharacterIterator
getCommittedText ()
AttributedCharacterIterator
getCommittedText (int beginIndex,
int endIndex)
int
getCommittedTextLength ()
action, add,
addComponentListener,
addFocusListener,
addInputMethodListener,
addKeyListener,
addMouseListener,
addMouseMotionListener, addNotify,
addPropertyChangeListener,
addPropertyChangeListener, bounds,
checkImage,
checkImage,
coalesceEvents, contains,
contains,
createImage, createImage,
deliverEvent, disable,
disableEvents,
dispatchEvent, doLayout,
enable,
enable,
enableEvents,
enableInputMethods,
firePropertyChange, getAlignmentX,
getAlignmentY,
getBackground,
getBounds,
getBounds, getColorModel,
getComponentAt,
getComponentAt,
getComponentOrientation, getCursor,
getDropTarget,
getFont,
getFontMetrics, getForeground,
getGraphics,
getHeight,
getInputContext,
getInputMethodRequests,
getLocale,
getLocation,
getLocation, getLocationOnScreen,
getMaximumSize,
getMinimumSize,
getName,
getParent,
getPeer,
getPreferredSize,
getSize,
getSize, getToolkit,
getTreeLock,
getWidth,
getX,
getY,
gotFocus,
handleEvent, hasFocus,
hide,
imageUpdate, inside,
invalidate,
isDisplayable,
isDoubleBuffered,
isEnabled,
isFocusTraversable,
isLightweight,
isOpaque,
isShowing,
isValid,
isVisible,
keyDown,
keyUp, layout,
list,
list,
list,
list,
list, locate,
location,
lostFocus, minimumSize,
mouseDown,
mouseDrag,
mouseEnter,
mouseExit,
mouseMove,
mouseUp, move,
nextFocus,
paintAll, paramString,
postEvent, preferredSize,
prepareImage,
prepareImage, print,
printAll,
processComponentEvent,
processEvent,
processFocusEvent,
processInputMethodEvent,
processKeyEvent,
processMouseEvent,
processMouseMotionEvent,
remove,
removeComponentListener,
removeFocusListener,
removeInputMethodListener,
removeKeyListener,
removeMouseListener,
removeMouseMotionListener, removeNotify,
removePropertyChangeListener,
removePropertyChangeListener, repaint,
repaint, repaint,
repaint, requestFocus,
reshape,
resize, resize,
setBackground,
setBounds,
setBounds,
setComponentOrientation,
setCursor,
setDropTarget, setEnabled,
setFont,
setForeground,
setLocale, setLocation,
setLocation,
setName,
setSize, setSize,
setVisible,
show,
show,
size,
toString,
transferFocus,
update, validate
public LWTextComponent(String name, boolean enableInputMethods)
name
- the component name to be displayed above
the textenableInputMethods
- whether to enable input
methods for this componentpublic void setFontSize(int size)
public void paint(Graphics g)
public AttributedCharacterIterator getCommittedText()
public AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex)
beginIndex
- the index of the first character of
the subrangeendIndex
- the index of the character following
the subrangepublic int getCommittedTextLength()
public AttributedCharacterIterator getDisplayText()
public TextLayout getTextLayout()
invalidateTextLayout()
,
getDisplayText()
public void invalidateTextLayout()
getTextLayout()
public Point getTextOrigin()
public Rectangle getCaretRectangle()
getCaret()
public Rectangle getCaretRectangle(TextHitInfo caret)
caret
- the text index for which to calculate a
caret rectanglepublic TextHitInfo getCaret()
public void insertCharacter(char c)
c
- the character to be insertedpublic void keyTyped(KeyEvent event)
public void keyPressed(KeyEvent event)
public void keyReleased(KeyEvent event)
public void focusGained(FocusEvent event)
public void focusLost(FocusEvent event)
Oracle and/or its affiliates Java Technology |
Copyright © 1993, 2018, Oracle and/or its affiliates. All rights reserved. |