|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.text.AbstractDocument javax.swing.text.PlainDocument com.ibm.as400.ui.framework.java.TextDocument
public class TextDocument extends 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));
Modifier and Type | Class and Description |
---|
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument |
---|
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement |
Modifier and Type | Field and Description |
---|
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 and Description |
---|
TextDocument(int maxLength)
Constructs a document which will only accept user input less than maxLength characters. |
TextDocument(int maxLength,
JComboBox comboBox)
Constructs a document for a JComboBox which will only accept user input less than maxLength characters. |
TextDocument(int maxLength,
JTextComponent textComponent)
Constructs a document for a JTextComponent which will only accept user input less than maxLength characters. |
Modifier and Type | Method and Description |
---|---|
int |
getMaxLength()
Returns the maximum length allowed by this document. |
void |
insertString(int offset,
String str,
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TextDocument(int maxLength)
maxLength
- The maximum length of input allowed by the user. A value of 0 does not restrict input.public TextDocument(int maxLength, JComboBox comboBox)
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.public TextDocument(int maxLength, JTextComponent textComponent)
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.Method Detail |
---|
public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException
insertString
in interface Document
insertString
in class PlainDocument
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.BadLocationException
- The given insert position is not valid.public int getMaxLength()
public void setMaxLength(int maxLength)
maxLength
- The maximum length of input allowed by the user. A value of 0 does not restrict input.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |