Accepts an optional Runnable that resets the editor on NumberFormatException, or a TextField or Spinner that is preemptively monitored for invalid input during typing, and restricts valid input to a specified range when committed.
- Author:
- Christoph Nahr
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an IntegerStringConverter.IntegerStringConverter(Runnable reset) Creates an IntegerStringConverter with an editor reset callback.IntegerStringConverter(javafx.scene.control.TextField input, int min, int max) Creates an IntegerStringConverter with the specified input range. -
Method Summary
Modifier and TypeMethodDescriptionstatic IntegerStringConverterCreates an IntegerStringConverter for the specified Spinner.fromString(String s) Converts the specified string into its integer value.voidSets the editor reset callback.Converts the specified integer into its string form.
-
Constructor Details
-
IntegerStringConverter
public IntegerStringConverter()Creates an IntegerStringConverter. Swallows NumberFormatException but does nothing in response untilsetReset(java.lang.Runnable)is defined. -
IntegerStringConverter
Creates an IntegerStringConverter with an editor reset callback. Specifyingnullhas the same effect as the default constructor.- Parameters:
reset- The Runnable to call upon NumberFormatException.
-
IntegerStringConverter
public IntegerStringConverter(javafx.scene.control.TextField input, int min, int max) Creates an IntegerStringConverter with the specified input range.Preemptively monitors input to reject any invalid characters during typing, restricts input to [
min,max] (inclusive) when valid text is committed, and resets input to the closest value to zero within [min,max] when invalid text is committed.- Parameters:
input- The TextField providing user-edited strings.min- The smallest valid integer value.max- The greatest valid integer value.- Throws:
NullPointerException- if input isnull
-
-
Method Details
-
createFor
Creates an IntegerStringConverter for the specified Spinner. Uses the TextField and minimum and maximum values of the specified Spinner for construction, and also sets the new IntegerStringConverter on itsSpinnerValueFactory.IntegerSpinnerValueFactory.- Parameters:
spinner- The Spinner to create an IntegerStringConverter for.- Returns:
- the new IntegerStringConverter
- Throws:
NullPointerException- ifspinnerisnull
-
setReset
Sets the editor reset callback.Specify
nullto clear a previously set Runnable. When creating an IntegerStringConverter for a TextField or Spinner, this callback is automatically defined to reset committed invalid input to the closest value to zero within the legal range. Setting a different callback will overwrite this functionality.- Parameters:
reset- The Runnable to call upon NumberFormatException.- See Also:
-
fromString
Converts the specified string into its integer value. Anull, empty, or otherwise invalid argument returns zero and also executes the editor reset callback, if any. -
toString
-