public class AutoResizingTextArea
extends javax.swing.JTextArea
JTextArea
that automatically resizes itself vertically. This component works best
when used in a layout that obeys preferred height of its components. For example, you can use a
BorderLayout
and place AutoResizingTextArea
to the north or south side. Similarly, you can
use a JideBoxLayout
and use FLEXIBLE or FIX as the constraint.javax.swing.JTextArea.AccessibleJTextArea
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 int |
DEFAULT_MAX_ROWS
Default maximum height of the text area in rows.
|
static int |
DEFAULT_MIN_ROWS
Default minimum height of the text area in rows.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
AutoResizingTextArea()
Creates a textarea with the default minimum and maximum number of rows.
|
AutoResizingTextArea(javax.swing.text.Document doc)
Create a new
AutoResizingTextArea using a Document . |
AutoResizingTextArea(javax.swing.text.Document doc,
java.lang.String text,
int minRows,
int maxRows,
int columns)
Constructs a new
AutoResizingTextArea with the specified number of rows and columns, and the given
model. |
AutoResizingTextArea(int minRows)
Creates a textarea with the specified minimum number of rows.
|
AutoResizingTextArea(int minRows,
int maxRows)
Creates a textarea with the specified minimum and maximum number of rows.
|
AutoResizingTextArea(int minRows,
int maxRows,
int columns)
Create a new
AutoResizingTextArea with a height bounded by the provided minimum and maximum row
counts and with its width dictated by the provided column count. |
AutoResizingTextArea(java.lang.String text)
Creates a textarea with the default minimum and maximum row count and the provided initial text.
|
AutoResizingTextArea(java.lang.String text,
int minRows,
int maxRows,
int columns)
Create a new
AutoResizingTextArea with a height bounded by the provided minimum and maximum row
counts and with its width dictated by the provided column count. |
Modifier and Type | Method and Description |
---|---|
int |
getMaxRows()
Gets the maximum number of rows that will be displayed.
|
int |
getMinRows()
Gets the minimum number of rows that will be displayed.
|
protected void |
numberOfRowsUpdated(int oldRow,
int newRow)
Called when the number of rows is updated.
|
void |
setMaxRows(int maxRows)
Sets the maximum number of rows that will be displayed.
|
void |
setMinRows(int minRows)
Sets the minimum number of rows that will be displayed
|
void |
setRows(int rows)
Sets the number of visible rows.
|
append, createDefaultModel, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, replaceRange, setColumns, setFont, setLineWrap, setTabSize, setWrapStyleWord
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, write
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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, 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, 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
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, processFocusEvent, 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 int DEFAULT_MAX_ROWS
public static final int DEFAULT_MIN_ROWS
public AutoResizingTextArea()
public AutoResizingTextArea(int minRows)
minRows
- The minimum number of rows that this textarea can have.public AutoResizingTextArea(int minRows, int maxRows)
minRows
- The minimum number of rows that this textarea can have.maxRows
- The maximum number of rows that this textarea can have.public AutoResizingTextArea(java.lang.String text)
text
- The initial text to display.public AutoResizingTextArea(int minRows, int maxRows, int columns)
AutoResizingTextArea
with a height bounded by the provided minimum and maximum row
counts and with its width dictated by the provided column count.minRows
- The minimum number of rows that this textarea can havemaxRows
- The maximum number of rows that this textarea can have.columns
- The number of columns that this textarea has.public AutoResizingTextArea(java.lang.String text, int minRows, int maxRows, int columns)
AutoResizingTextArea
with a height bounded by the provided minimum and maximum row
counts and with its width dictated by the provided column count. The textarea is sized to fit the provided text.text
- The initial text to display in the textarea.minRows
- The minimum number of rows that this textarea can havemaxRows
- The maximum number of rows that this textarea can have.columns
- The number of columns that this textarea has.java.lang.IllegalArgumentException
- if the rows or columns arguments are negative.public AutoResizingTextArea(javax.swing.text.Document doc)
AutoResizingTextArea
using a Document
. The document will be set to the
text area using JTextComponent.setDocument(javax.swing.text.Document)
.doc
- the document.public AutoResizingTextArea(javax.swing.text.Document doc, java.lang.String text, int minRows, int maxRows, int columns)
AutoResizingTextArea
with the specified number of rows and columns, and the given
model. All of the constructors feed through this constructor.doc
- the model to use, or create a default one if nulltext
- the text to be displayed, null if noneminRows
- the minimum number of rows >= 0maxRows
- the maximum number of rows >= 0columns
- the number of columns >= 0java.lang.IllegalArgumentException
- if the rows or columns arguments are negative.public void setRows(int rows)
setRows
in class javax.swing.JTextArea
rows
- The number of rows to showprotected void numberOfRowsUpdated(int oldRow, int newRow)
oldRow
- the previous row count.newRow
- the new row count.public int getMaxRows()
setMaxRows(int)
or passed
in using constructor such as AutoResizingTextArea(int,int)
.public void setMaxRows(int maxRows)
maxRows
- The maximum number of rows.public int getMinRows()
setMinRows(int)
or passed
in using constructor such as AutoResizingTextArea(int,int)
.public void setMinRows(int minRows)
minRows
- The minimum number of rows.