java - Alphabets validation of jtextfield -


I just though pressed another key JTextField should not display them try to display characters jtextfield.Even Only characters are to be displayed. Please help me with this ..

one

  import Java.awt.EventQueue; Import javax.swing.JFrame; Import javax.swing.JTextField; Import javax.swing.UIManager; Import javax.swing.UnsupportedLookAndFeelException; Import javax.swing.text.AbstractDocument; Import javax.swing.text.AttributeSet; Import javax.swing.text.BadLocationException; Import javax.swing.text.DocumentFilter; Public category testfilter {public static zero main (string [] args) {new test filter (); } Public testfilter () {EventQueuekinvokeLater (new Rnnabl) {@ Override public Boyd run () {{UIManagerksetLookAndFeel ()}} catch (Exception Clasnotfound | Instentiaasn Apoksekshn | illegal Aksesaksepshn | unsupported lock and Eiffel Akspeshment ex) {ex .printStackTrace ();} JTextField area = new JTextField (10), ((AbstractDocument) field.getDocument ()) setDocumentFilter (new CharFilter ()) ;. JFrame frame = new JFrame ("test"); Frame.setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE); Frame.setLayout (New GridBagLayout ()); Frame.add (area); Frame.pack (); Frame.setLocationRelativeTo (zero); Frame.setVisible (true);}}); } Public class CharFilter DocumentFilter {@Override public void insertString (DocumentFilter.FilterBypass FB, offset int, string, AttributeSet attr) throws BadLocationException {StringBuilder buffer = extends new StringBuilder (string); For (int i = buffer.lamp () - 1; i> = 0; i--) {char ch = buffer.chart (i); If (! Alphabetic (ch)) {Buffer. Dilature dust (i); }} Super.insertString (fb, offset, buffer.testrein (), atri); } @Override public void space (DocumentFilter.FilterBypass FB, int offset, throws int length, string, AttributeSet Attr) BadLocationException {If (length & gt; 0) {fb.remove (offset, length); } InsertString (fb, offset, string, attr); }}}  

You also find helpful


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -