Hello, I was wondering how to limit the size of a JTextfield to say 5 characters so that onlt 5 letters can fit. The code does not work ; JTextField field = new JTextField(5) ; why doesn't this work? any suggestions? yours respectfully Avin Sinanan
yours respectfully<br />Avin Sinanan
posted 14 years ago
The 5 in the constructor does not refer to characters but columns. It is used to calculate the preferred size. Unless a monospaced font is used, that space can be taken up differently by say a "W" and a "i". If you want the size different, set the preferred size yourself. It also does not limit the entry to 5. You need to create a document to handle that. Take a look at the API example and modify it for your use.