About Author

Engineering and Senior Developer, HTML5, CSS3, JavaScript, PHP, Python, Java, Android Developer, friend and father.

Social
Share In

RestrictedTextField is a small library inspired in the limited behavior of Swing componen provides, one of the common problems in use the component, it is very complex to manage the content that is being written, that is, there is no way to automatically validate the user to type certain characters we want, unless it is by manual code.

It is for this reason that theRestrictedTextFieldlibrary provides an easy way to manipulate the component providing some utility functions that could benefit more than one person.

Latest Version (1.0)

The lastest version contain the next functions

  • Allow limit the jTextField to only accept letters.
  • Allow limit the jTextField to only accept numbers.
  • Allow limit the jTextField to only accept one numbers of characters defined.
  • Allow writing only alphanumeric characters.
  • Allow manage the characters predefined, regardless if it is numeric, letter, or simultaneous.
  • Allow accept spaces

The library use is realy very simple

Download Library

Add library to Project

Import to proyect

Import library in your package

import Atxy2k.CustomTextField.RestrictedTextField;

Init instances and restrictions

Example Result

Up

Methods

RestrictedTextField library provide some methods to your easy use

setLimit(Int number)

Assign the text field write a limit, for example, if we were using a zip code, the limit would be 5. By default the text field limit is 20 characters.

setOnlyNums(boolean)

Merely in the text field you can type only numbers (not including spaces), the default value is false.

setOnlyText(boolean)

Merely in the text field only you can type text (not including spaces), the default value is false.

setAcceptSpace(boolean )

Allows the blanks in the text field, regardless of whether any of the above methods has been executed, the default value is false

setOnlyAlphanumeric(boolean )

Merely in the text field can be written only alphanumeric characters (not including spaces), the default value is false.

restore()

Resets the jtextfield to default configuration

setOnlyCustomCharacters(boolean )

Merely in the text field can be written only certain characters that we provide these, also, are introduced into a text string as the second parameter of the constructor

r1 = new RestrictedTextField(campoTexto, "abcde");

Comments