Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Restrict TextArea to allow IP Addresses only JavaFX with FXML

2978210Jun 24 2015 — edited Jun 27 2015

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, 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.  Is this even the correct way of doing it?


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_\\u005F]") || string.isEmpty()){

          super.replaceText(il, il, string);

       }

   }

    @Override

    public void replaceSelection(String string) {

        super.replaceSelection(string);

    }

     }

In my FXML File I calling it as <RestrictIpInputTextArea ......

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 25 2015
Added on Jun 24 2015
6 comments
1,740 views