Package com.jidesoft.swing
Class AutoResizingTextArea
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextArea
com.jidesoft.swing.AutoResizingTextArea
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,Scrollable
An extended version of
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.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JTextArea
JTextArea.AccessibleJTextArea
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default maximum height of the text area in rows.static final int
Default minimum height of the text area in rows.Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a textarea with the default minimum and maximum number of rows.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 newAutoResizingTextArea
with a height bounded by the provided minimum and maximum row counts and with its width dictated by the provided column count.AutoResizingTextArea
(String text) Creates a textarea with the default minimum and maximum row count and the provided initial text.AutoResizingTextArea
(String text, int minRows, int maxRows, int columns) Create a newAutoResizingTextArea
with a height bounded by the provided minimum and maximum row counts and with its width dictated by the provided column count.Create a newAutoResizingTextArea
using aDocument
.AutoResizingTextArea
(Document doc, String text, int minRows, int maxRows, int columns) Constructs a newAutoResizingTextArea
with the specified number of rows and columns, and the given model. -
Method Summary
Modifier and TypeMethodDescriptionint
Gets the maximum number of rows that will be displayed.int
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
setDocument
(Document doc) 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 displayedvoid
setRows
(int rows) Sets the number of visible rows.Methods inherited from class javax.swing.JTextArea
append, createDefaultModel, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, replaceRange, setColumns, setFont, setLineWrap, setTabSize, setWrapStyleWord
Methods inherited from class javax.swing.text.JTextComponent
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, modelToView2D, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, viewToModel2D, write
Methods inherited from class javax.swing.JComponent
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
Methods 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, validateTree
Methods inherited from class java.awt.Component
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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
DEFAULT_MAX_ROWS
public static final int DEFAULT_MAX_ROWSDefault maximum height of the text area in rows.- See Also:
-
DEFAULT_MIN_ROWS
public static final int DEFAULT_MIN_ROWSDefault minimum height of the text area in rows.- See Also:
-
-
Constructor Details
-
AutoResizingTextArea
public AutoResizingTextArea()Creates a textarea with the default minimum and maximum number of rows. -
AutoResizingTextArea
public AutoResizingTextArea(int minRows) Creates a textarea with the specified minimum number of rows.- Parameters:
minRows
- The minimum number of rows that this textarea can have.
-
AutoResizingTextArea
public AutoResizingTextArea(int minRows, int maxRows) Creates a textarea with the specified minimum and maximum number of rows.- Parameters:
minRows
- The minimum number of rows that this textarea can have.maxRows
- The maximum number of rows that this textarea can have.
-
AutoResizingTextArea
Creates a textarea with the default minimum and maximum row count and the provided initial text. The textarea is sized to fit the provided text.- Parameters:
text
- The initial text to display.
-
AutoResizingTextArea
public AutoResizingTextArea(int minRows, int maxRows, int columns) Create a newAutoResizingTextArea
with a height bounded by the provided minimum and maximum row counts and with its width dictated by the provided column count.- Parameters:
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.
-
AutoResizingTextArea
Create a newAutoResizingTextArea
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.- Parameters:
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.- Throws:
IllegalArgumentException
- if the rows or columns arguments are negative.
-
AutoResizingTextArea
Create a newAutoResizingTextArea
using aDocument
. The document will be set to the text area usingsetDocument(javax.swing.text.Document)
.- Parameters:
doc
- the document.
-
AutoResizingTextArea
Constructs a newAutoResizingTextArea
with the specified number of rows and columns, and the given model. All of the constructors feed through this constructor.- Parameters:
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 >= 0- Throws:
IllegalArgumentException
- if the rows or columns arguments are negative.
-
-
Method Details
-
setRows
public void setRows(int rows) Sets the number of visible rows. The row value will be forced to the boundaries of the range [minRows ... maxRows] if it is outside that range. -
numberOfRowsUpdated
protected void numberOfRowsUpdated(int oldRow, int newRow) Called when the number of rows is updated. By default, it will get the parent scroll pane and call revalidate. Subclass can override it to customize the behavior when number of rows is updated.- Parameters:
oldRow
- the previous row count.newRow
- the new row count.
-
getMaxRows
public int getMaxRows()Gets the maximum number of rows that will be displayed. You can set it usingsetMaxRows(int)
or passed in using constructor such asAutoResizingTextArea(int, int)
.- Returns:
- the maximum number of rows that will be displayed.
-
setMaxRows
public void setMaxRows(int maxRows) Sets the maximum number of rows that will be displayed.- Parameters:
maxRows
- The maximum number of rows.
-
getMinRows
public int getMinRows()Gets the minimum number of rows that will be displayed. You can set it usingsetMinRows(int)
or passed in using constructor such asAutoResizingTextArea(int, int)
.- Returns:
- the minimum number of rows that will be displayed.
-
setMinRows
public void setMinRows(int minRows) Sets the minimum number of rows that will be displayed- Parameters:
minRows
- The minimum number of rows.
-
setDocument
- Overrides:
setDocument
in classJTextComponent
-
getPreferredScrollableViewportSize
- Specified by:
getPreferredScrollableViewportSize
in interfaceScrollable
- Overrides:
getPreferredScrollableViewportSize
in classJTextArea
-