Hi, I have posted this message on SCJP and only Andrew gave me a reply. Thanks to Andrew. I would like to post int here to see if there are any more suggestions. To book a room, user should enter an 8-digit number as client ID. How to set the maximum input length of the JTextField, so that user can not enter any more digits after 8 digits? The following code does not work. JTextFiled t1 = new JTextField(8); t1.setColumns(8); The origianl thread is at: http://www.coderanch.com/t/241875/java-programmer-SCJP/certification/set-maximum-input-length-JTextField Thanks to any suggestion.
Well, Andrew's answer is the best answer. Making a PlainDocument that accepts only numbers and only up to a certain number of numbers, then PlainDocuments and extending JTextField is the way to go. Andrew posted a good tutorial, and if I was at my desk at work and not onsite at one of our regions, I'd post the simple code that you need. But I guess it is better this way because you can learn to use PlainDocuments on your own. Mark
Is it necessary to use text field to book the record? can't we use the editable column once user double clicks on the record to book it, and make only the owner column editable. is this bad idea?
Joined: Apr 09, 2003
Hi, Ganapathy, I think it is fine to use editable column. The question I raised is how to ensure the input is an 8-digit number. For example, "shan1111", "123456789" are incorrect and should be rejected. The progam can check it after user presses "book" button, or does not allow such input on fly. shan