Created
February 2, 2014 12:03
-
-
Save tonfever/8767395 to your computer and use it in GitHub Desktop.
a custom JavaFX numeric textbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NumberTextField extends TextField { | |
@Override | |
public void replaceText(int start, int end, String text) | |
{ | |
if (validate(text)) | |
{ | |
super.replaceText(start, end, text); | |
} | |
} | |
@Override | |
public void replaceSelection(String text) | |
{ | |
if (validate(text)) | |
{ | |
super.replaceSelection(text); | |
} | |
} | |
private boolean validate(String text) | |
{ | |
if (text.matches("[0-9]") || text == "") | |
{ | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment