com.ibm.as400.ui.framework.java
Class TextDocument
java.lang.Object
|
+--javax.swing.text.AbstractDocument
|
+--javax.swing.text.PlainDocument
|
+--com.ibm.as400.ui.framework.java.TextDocument
- All Implemented Interfaces:
- javax.swing.text.Document, java.io.Serializable
- public class TextDocument
- extends javax.swing.text.PlainDocument
A replacement document for JTextComponent and JComboBox objects which
limits the maximum number of characters allowed as input by the user.
When a TextDocument has been assigned to a JTextComponent or JComboBox,
the control will not allow input past the specified number of characters.
The only exception are items in the JComboBox drop down. These can still
be selected or typed regardless of their length.
The following code creates a TextDocument to restrict the length of a
JTextComponent to 12.
// Get the text component from the panel manager
JTextComponent tc = (JTextComponent)m_panel.getComponent("mytextfield");
// Assign a new TextDocument to restrict length to 12.
tc.setDocument(new TextDocument(12));
The following code creates a TextDocument to restrict the length of a
JComboBox to 10.
// Get the combo box from the panel manager
JComboBox cb = (JComboBox)m_panel.getComponent("mycombobox");
// Get the internal text component and assign a new TextDocument
JTextComponent tc = (JTextComponent)cb.getEditor().getEditorComponent();
tc.setDocument(new TextDocument(10, cb));
- Since:
- v5r1m0
- See Also:
- Serialized Form
Inner classes inherited from class javax.swing.text.AbstractDocument |
javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement |
Fields inherited from class javax.swing.text.PlainDocument |
lineLimitAttribute, tabSizeAttribute |
Fields inherited from class javax.swing.text.AbstractDocument |
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName |
Fields inherited from interface javax.swing.text.Document |
StreamDescriptionProperty, TitleProperty |
Constructor Summary |
TextDocument(int maxLength)
Constructs a document which will only accept user input less
than maxLength characters. |
TextDocument(int maxLength,
javax.swing.JComboBox comboBox)
Constructs a document for a JComboBox which will only accept user input less
than maxLength characters. |
TextDocument(int maxLength,
javax.swing.text.JTextComponent textComponent)
Constructs a document for a JTextComponent which will only accept user input less
than maxLength characters. |
Method Summary |
int |
getMaxLength()
Returns the maximum length allowed by this document. |
void |
insertString(int offset,
java.lang.String str,
javax.swing.text.AttributeSet attr)
Inserts a string into the document. |
void |
setMaxLength(int maxLength)
Sets the maximum length allowed by this document. |
Methods inherited from class javax.swing.text.PlainDocument |
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate |
Methods inherited from class javax.swing.text.AbstractDocument |
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, setAsynchronousLoadPriority, setDocumentProperties, writeLock, writeUnlock |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TextDocument
public TextDocument(int maxLength)
- Constructs a document which will only accept user input less
than maxLength characters.
- Parameters:
maxLength
- The maximum length of input allowed by the user. A value of 0 does not restrict input.- Since:
- v5r1m0
TextDocument
public TextDocument(int maxLength,
javax.swing.JComboBox comboBox)
- Constructs a document for a JComboBox which will only accept user input less
than maxLength characters.
The JComboBox to be restricted must be passed.
- Parameters:
maxLength
- The maximum length of input allowed by the user. A value of 0 does not restrict input.comboBox
- The JComboBox control to be restricted.- Since:
- v5r1m0
TextDocument
public TextDocument(int maxLength,
javax.swing.text.JTextComponent textComponent)
- Constructs a document for a JTextComponent which will only accept user input less
than maxLength characters.
The JTextComponent to be restricted must be passed.
- Parameters:
maxLength
- The maximum length of input allowed by the user. A value of 0 does not restrict input.textComponent
- The JTextComponent control to be restricted.- Since:
- v5r1m0
insertString
public void insertString(int offset,
java.lang.String str,
javax.swing.text.AttributeSet attr)
throws javax.swing.text.BadLocationException
- Inserts a string into the document.
- Overrides:
insertString
in class javax.swing.text.AbstractDocument
- Parameters:
offset
- The offset into the document to insert the content.str
- The string to insert.a
- The attributes to be associated with the inserted string.- Throws:
javax.swing.text.BadLocationException
- The given insert position is not valid.- Since:
- v5r1m0
getMaxLength
public int getMaxLength()
- Returns the maximum length allowed by this document.
- Returns:
- The maximum length allowed as input.
- Since:
- v5r1m0
setMaxLength
public void setMaxLength(int maxLength)
- Sets the maximum length allowed by this document.
- Parameters:
maxLength
- The maximum length of input allowed by the user. A value of 0 does not restrict input.- Since:
- v5r1m0