How to set a limit on how to input the user, I mean that users can only have 2 or 4 integers and do not input such as More
code:
JLabel dated = new JLabel ("| Date:"); DateD.setBounds (170,270, 120, 25); DateDD = new JTextField (); DateDD.setBounds (235,270, 20, 25); Using text
The rule is made as follows: - Document filter in class maximum sectors (Private Prime Max Lamp; Public Maximum Sector) (number of maximumLength = 10; // approved characters) @Override Public Zero insertString ( FilterBypass FB, offset int, string string, AttributeSet attr throws BadLocationException {if (maxLength & gt; 0 & amp; amp; amp; amp; Fb.getDocument () getLength () + String .length () & lt; = maxLength) {super.insertString (FB, offset, string, attr);}} @ Override instead of public spaces (filtered FB, int offset, int length, string text, attributate etter) Badlocation throws the expression (if (Fbgate document). GetLength () + text length () - length) & lt; = maximum length) super.replace (FB, offset, length, text, ethers);}} Then you DocumentFilter your JTextField component below Can doors set: - ((AbstractDocument) dateDD.getDocument ()) setDocumentFilter (New MaximumCharacters ()).
No comments:
Post a Comment