Skip to content

Instantly share code, notes, and snippets.

@tonfever
Created February 2, 2014 12:03
Show Gist options
  • Save tonfever/8767395 to your computer and use it in GitHub Desktop.
Save tonfever/8767395 to your computer and use it in GitHub Desktop.
a custom JavaFX numeric textbox
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