0

I have a textfield, and that only accept integer numbers. If user input charter type value it shows JOptionpane Error Message and when user click on the ok button in optionpane message the textfield clear itself

public void nosgetit(DocumentEvent documentEvent){
        DocumentEvent.EventType type = documentEvent.getType();
        if(type.equals(DocumentEvent.EventType.CHANGE)){

        }
        if(type.equals(DocumentEvent.EventType.INSERT)){

                String ns=nos_txt.getText();
                char [] c=ns.toCharArray();
                for(int i=0; i < ns.length(); i++){
                   if ( !Character.isDigit(c[i])){
                       JOptionPane.showMessageDialog(null, "You must input number", "ERROR",
                                      JOptionPane.ERROR_MESSAGE);

                   } 
                }
        }
        if(type.equals(DocumentEvent.EventType.REMOVE)){

        }
    }
2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

What exactly is the question?
You can clear a text field by simply setting its text to "", but remember that will create another call to your DocumentEvent listener, which you may need to handle.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.