I have a TextArea that I am trying to restrict user inputs to allow only IP addresses format in that Area. So I thought of only allowing digits and decimal points. For multiple IPs, One IP per line, so the TextArea needs to accept new lines. For the most part what I have below is working except for delete. I can't delete any entry even if I am using the associate Unicode. I am running MAC OS 10, not sure if it makes any difference or not but the info is out there just in case.
public class RestrictIpInputTextArea extends TextArea {
@Override
public void replaceText(int i, int il, String string){
if(string.matches("[0-9_\\u000A_\\u232B_\\u0008_\\u2421_._\\u007F]") || string.isEmpty()){
super.replaceText(il, il, string);
}
}
@Override
public void replaceSelection(String string) {
super.replaceSelection(string);
}
I was able to find out the solution for it. Visit the link below for more reference. http://docs.oracle.com/javafx/2/ui_controls/custom.htm However, I still want to explore TextFormatter function deployed in JavaFX 8U40
public class numericValue extends TextArea {
@Override
public void replaceText(int start, int end, String text) {
String old = getText();
if (text.matches("[0-9_._\\u000A]*")) {
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text) {
String old = getText();
if (text.matches("[0-9_._\\u000A]*")) {
super.replaceSelection(text);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.