|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.swing.visuals.LimitedTextField
public class LimitedTextField
This class extends JTextField to use the LimitPlainDocument class as the default document. This private document class supports the component's maxCharacters property. If a user operation would exceed the maximum number of characters allowable, no new characters are entered. And, if the beepEnabled property (off by default) is enabled the control will beep when such operations are attempted. This class supports all the constructors of JTextField except the one which takes a document as one of the arguments - there is no utility to using this class if a document is supplied for use and in such a case the maxCharacters and beepEnabled properties are meaningless. Typical usage is as follows: LimitedTextField ltf = new LimitedTextField(); ltf.setMaxCharacters(32); // allow a max of 32 characters The implementation of the document class is based on the sample subclass shown in the 1.4 Javadoc for JTextField. Do note that in the current implementation of setText() is called with a string longer than maxCharacters any previous contents of the text field are erased. If this is an issue in a use case, a reimplementation of this class using DocumentFilters (introduced in 1.4) may be an option.
Constructor Summary | |
---|---|
LimitedTextField()
Constructs a new empty LimitedTextField - identical to the corresponding JTextField constructor. |
|
LimitedTextField(int columns)
Constructs a new empty LimitedTextField with the specified number of columns - identical to the corresponding JTextField constructor. |
|
LimitedTextField(java.lang.String text)
Constructs a new LimitedTextField initialized with the specified text - identical to the corresponding JTextField constructor. |
|
LimitedTextField(java.lang.String text,
int columns)
Constructs a new LimitedTextField initialized with the specified text and columns. |
Method Summary | |
---|---|
protected javax.swing.text.Document |
createDefaultModel()
|
int |
getMaxCharacters()
Gets the maximum number of characters the LimitedTextField will allow. |
boolean |
isBeepEnabled()
Gets the value of the beepEnabled property. |
void |
setBeepEnabled(boolean beepEnabled)
Sets the beepEnabled property. |
void |
setMaxCharacters(int maxCharacters)
Sets the maximum number of characters the LimitedTextField will allow. |
Constructor Detail |
---|
public LimitedTextField()
public LimitedTextField(int columns)
columns
- the number of columns to use to calculate the preferred widthpublic LimitedTextField(java.lang.String text)
text
- the initial textpublic LimitedTextField(java.lang.String text, int columns)
text
- the initial textcolumns
- the number of columns to use to calculate the preferred widthMethod Detail |
---|
protected javax.swing.text.Document createDefaultModel()
createDefaultModel
in class javax.swing.JTextField
public int getMaxCharacters()
public void setMaxCharacters(int maxCharacters)
maxCharacters
- the maximum number of characters allowed in the LimitedTextFieldpublic boolean isBeepEnabled()
public void setBeepEnabled(boolean beepEnabled)
beepEnabled
- the value to set
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |