public class JEditTextArea
extends javax.swing.JComponent
To use it in your app, treat it like any other component, for example:
JEditTextArea ta = new JEditTextArea(); ta.setTokenMarker(new JavaTokenMarker()); ta.setText("public class Test {\n" + " public static void main(String[] args) {\n" + " System.err.println(\"Hello World\");\n" + " }\n" + "}");
javax.swing.JComponent.AccessibleJComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
JEditTextArea(TextAreaDefaults defaults,
SyntaxDocument document,
boolean paintInvalid)
Creates a new JEditTextArea with the specified settings.
|
Modifier and Type | Method and Description |
---|---|
void |
blinkCaret()
Blinks the caret.
|
void |
copy()
Places the selected text into the clipboard.
|
void |
cut()
Deletes the selected text from the text area and places it into the
clipboard.
|
int |
getCaretLine()
Returns the caret line.
|
int |
getCaretPosition()
Returns the caret position.
|
javax.swing.text.Document |
getDocument()
Returns the document this text area is editing.
|
int |
getDocumentLength()
Returns the length of the document.
|
int |
getElectricScroll()
Returns the number of lines from the top and button of the text area that
are always visible.
|
int |
getFirstLine()
Returns the line displayed at the text area's origin.
|
InputHandler |
getInputHandler()
Returns the input handler.
|
int |
getLineCount()
Returns the number of lines in the document.
|
int |
getLineEndOffset(int line)
Returns the end offset of the specified line.
|
int |
getLineStartOffset(int line)
Returns the start offset of the specified line.
|
java.lang.CharSequence |
getLineText(int lineIndex)
Returns the text on the specified line.
|
int |
getMagicCaretPosition()
Returns the `magic' caret position.
|
int |
getMarkPosition()
Returns the mark position.
|
java.lang.String |
getSelectedText()
Returns the selected text, or null if no selection is active.
|
int |
getSelectionEnd()
Returns the selection end offset.
|
int |
getSelectionStart()
Returns the selection start offset.
|
java.lang.String |
getText()
Returns the entire text of this text area.
|
java.lang.String |
getText(int start,
int len)
Returns the specified substring of the document.
|
void |
getText(int start,
int len,
javax.swing.text.Segment segment)
Copies the specified substring of the document into a segment.
|
int |
getVisibleLines()
Returns the number of lines visible in this text area.
|
boolean |
isEditable()
Returns true if this text area is editable, false otherwise.
|
boolean |
isModified()
Return whether the text content has been modified from the "unmodified"
state.
|
boolean |
isOverwriteEnabled()
Returns whether overwrite mode is active.
|
boolean |
isSelectionRectangular()
Returns true if the selection is rectangular, false otherwise.
|
int |
lineToY(int line)
Converts a line index to a y co-ordinate.
|
int |
offsetToX(int line,
int offset)
Converts an offset in a line into an x co-ordinate.
|
int |
offsetToX2(int line,
int offset)
Converts an offset in a line into an x co-ordinate.
|
void |
overwriteSetSelectedText(java.lang.String str)
Similar to
setSelectedText() , but overstrikes the appropriate
number of characters if overwrite mode is enabled. |
void |
paste()
Inserts the clipboard contents into the text.
|
void |
processKeyEvent(java.awt.event.KeyEvent e)
Forwards key events directly to the input handler.
|
void |
removeNotify()
Called by the AWT when this component is removed from it's parent.
|
void |
resetModified()
Reset the "modified" state.
|
void |
scrollTo(int line,
int offset)
Ensures that the specified line and offset is visible by scrolling the
text area if necessary.
|
void |
scrollToCaret()
Ensures that the caret is visible by scrolling the text area if
necessary.
|
void |
select(int start,
int end)
Selects from the start offset to the end offset.
|
void |
selectAll()
Selects all text in the document.
|
void |
setCaretPosition(int caret)
Sets the caret position.
|
void |
setCaretVisible(boolean caretVisible)
Sets if the caret should be visible.
|
void |
setEditingFocus()
Sets the focus to this TextArea, so this component is instantly
registered for key press events.
|
void |
setFirstLine(int firstLine)
Sets the line displayed at the text area's origin without updating the
scroll bars.
|
void |
setFont(java.awt.Font font)
Set the TextArea font
|
void |
setHorizontalOffset(int horizontalOffset)
Sets the horizontal offset of drawn lines.
|
void |
setMagicCaretPosition(int magicCaret)
Sets the `magic' caret position.
|
void |
setOrigin(int firstLine,
int horizontalOffset)
A fast way of changing both the first line and horizontal offset.
|
void |
setOverwriteEnabled(boolean overwrite)
Sets whether overwrite mode is active.
|
void |
setSelectedText(java.lang.String selectedText)
Replaces the selection with the specified text.
|
void |
setSelectionRectangular(boolean rectangleSelect)
Sets if the selection should be rectangular.
|
void |
setText(java.lang.String text)
Sets the entire text of this text area.
|
void |
updateScrollBars()
Updates the state of the scroll bars.
|
int |
xToOffset(int line,
int x)
Converts an x co-ordinate to an offset within a line.
|
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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
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, 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, getAccessibleContext, 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, 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
public JEditTextArea(@NotNull TextAreaDefaults defaults, @NotNull SyntaxDocument document, boolean paintInvalid)
defaults
- the default settingspaintInvalid
- whether invalid lines should be painted as red
tildespublic void setFont(@NotNull java.awt.Font font)
setFont
in class javax.swing.JComponent
font
- font@NotNull public InputHandler getInputHandler()
public void setCaretVisible(boolean caretVisible)
caretVisible
- true if the caret should be visible, false otherwisepublic void blinkCaret()
public int getElectricScroll()
public void updateScrollBars()
public int getFirstLine()
public void setFirstLine(int firstLine)
public int getVisibleLines()
public void setHorizontalOffset(int horizontalOffset)
horizontalOffset
- offset The new horizontal offsetpublic void setOrigin(int firstLine, int horizontalOffset)
firstLine
- the new first linehorizontalOffset
- the new horizontal offsetpublic void scrollToCaret()
public void setEditingFocus()
public void scrollTo(int line, int offset)
line
- the line to scroll tooffset
- the offset in the line to scroll topublic int lineToY(int line)
line
- the linepublic int offsetToX(int line, int offset)
line
- the lineoffset
- the offset, from the start of the linepublic int offsetToX2(int line, int offset)
line
- the lineoffset
- the offset, from the start of the linepublic int xToOffset(int line, int x)
line
- the linex
- the x co-ordinate@NotNull public javax.swing.text.Document getDocument()
public int getDocumentLength()
getDocument().getLength()
.public int getLineCount()
public int getLineStartOffset(int line)
line
- the linepublic int getLineEndOffset(int line)
line
- the line@NotNull public java.lang.String getText()
public void setText(@NotNull java.lang.String text)
@Nullable public java.lang.String getText(int start, int len)
start
- the start offsetlen
- the length of the substringpublic void getText(int start, int len, @NotNull javax.swing.text.Segment segment)
start
- the start offsetlen
- the length of the substringsegment
- the segment@NotNull public java.lang.CharSequence getLineText(int lineIndex)
lineIndex
- the linepublic int getSelectionStart()
public int getSelectionEnd()
public int getCaretPosition()
public int getCaretLine()
public int getMarkPosition()
getCaretPosition()
public void setCaretPosition(int caret)
caret
- the caret positionselect(int, int)
public void selectAll()
public void select(int start, int end)
start
- the start offsetend
- the end offset@Nullable public java.lang.String getSelectedText()
public void setSelectedText(@NotNull java.lang.String selectedText)
selectedText
- the replacement text for the selectionpublic boolean isEditable()
public int getMagicCaretPosition()
public void setMagicCaretPosition(int magicCaret)
magicCaret
- the magic caret positionpublic void overwriteSetSelectedText(@NotNull java.lang.String str)
setSelectedText()
, but overstrikes the appropriate
number of characters if overwrite mode is enabled.str
- the stringsetSelectedText(String)
,
isOverwriteEnabled()
public boolean isOverwriteEnabled()
public void setOverwriteEnabled(boolean overwrite)
overwrite
- whether overwrite mode is activepublic boolean isSelectionRectangular()
public void setSelectionRectangular(boolean rectangleSelect)
rectangleSelect
- true if the selection should be rectangular, false
otherwisepublic void cut()
public void copy()
public void paste()
public void removeNotify()
removeNotify
in class javax.swing.JComponent
public void processKeyEvent(@NotNull java.awt.event.KeyEvent e)
processKeyEvent
in class javax.swing.JComponent
public boolean isModified()
true
if the text content has been modified, or false
if it is unmodifiedpublic void resetModified()