uic.model
Class UICRestrictedDocument
java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.PlainDocument
uic.model.UICRestrictedDocument
- All Implemented Interfaces:
- Document, Serializable
- public class UICRestrictedDocument
- extends PlainDocument
A document which you can set on things like a JTextField or JTextArea which limits input the specified chars.
Example which only takes integers as the argument; all others will be rejected:
tfMxSize = new UICTextField();
tfMxSize.setDocument(new UICRestrictedDocument(UICRestrictedDocument.ALLOW_ABC));
Another example where both integers and alphanumeric (abc as well as ABC) are accepted.
myText = new UICTextField();
myText.setDocument(new UICRestrictedDocument(
UICRestrictedDocument.ALLOW_INTEGERS + UICRestrictedDocument.ALLOW_ABC));
- Since:
- 1.2
- See Also:
- Serialized Form
Methods inherited from class javax.swing.text.AbstractDocument |
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ALLOW_INTEGERS
public static final int ALLOW_INTEGERS
- See Also:
- Constant Field Values
ALLOW_ABC
public static final int ALLOW_ABC
- See Also:
- Constant Field Values
ALLOW_ALL
public static final int ALLOW_ALL
- See Also:
- Constant Field Values
ALLOW_FILESYSTEM_CHARS
public static final int ALLOW_FILESYSTEM_CHARS
- See Also:
- Constant Field Values
UICRestrictedDocument
public UICRestrictedDocument(int type)
- Constructor with type of chars allowed.
- Parameters:
type
- any combination of ALLOW_* integers like found on this class.
UICRestrictedDocument
public UICRestrictedDocument(String characters)
UICRestrictedDocument
public UICRestrictedDocument(char[] characters)
keepDocumentSingleLine
public void keepDocumentSingleLine(boolean on)
- Setting this boolean to true will convert any '\n' to a space which will then be checked.
If you have a single line document the pasting of an newline character will result
in a bad document, or a failure depending on whether the newline character is an allowed
character. Both situations are not really wanted; so if you want to paste a multiline text
setting this boolean to true will convert newline characters to spaces unconditionally.
If you allow spaces in your document the paste will then succeed, resulting in a a single
line document.
addAllowedCharacters
public void addAllowedCharacters(String characters)
addAllowedCharacters
public void addAllowedCharacters(char[] characters)
setMaximumAllowedColumns
public void setMaximumAllowedColumns(int num)
- Set the maximum column size of this document.
Notice that the document will not be changed, only that extra characters will not be
allowed above the max.
getMaximumAllowedColumns
public int getMaximumAllowedColumns()
insertString
public void insertString(int offs,
String str,
AttributeSet a)
throws BadLocationException
- overloaded method to limit the characters the user can add
- Throws:
BadLocationException
Copyright © 2002,2003 Thomas Zander Available under the Free Apache licence