• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JTABLE + JTEXTFIELD....

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there any way i can create an uneditable JTABLE,....
also is there a function to fix the number of user input in a TextField, eg. a user can't enter more than 3 digits in a salary textfield....
thks !
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your first question is covered in your other post, so I'll ignore it here.
As for limiting the input to a TextField - no, there doesn't seem to be a function to do this, unfortunately (though I'd love it if someone pointed out I'm wrong about this). You may have to create a subclass of TextField which adds some sort of listener so that you can "intercept" user attempts to change the field, and pass them on to the component only if they don't create an invalid input. I'm thinking you need InputMethodListener for this, but you may also look at using KeyListener or TextListener. If you get it working, I'd love to see it.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I realize this is somewhat late, but I have an answer to the question to limiting the input in a JTextField. Maybe someone else searching for the same answer will find it.
You can extend the DefaultStyledDocument class which will allow you to test the data being entered into a JTextField as it is being entered. You will need to declare the extended document class and pass it the JTextField as an argument. In your initialization you will need to use the setDocument() method of the JTextField in question to this instance of the document class. The following code limits the range of input into a JTextField from 0 to 100. The code causes a beep and an error message when you get beyond these values.

[This message has been edited by Lon Allen (edited August 07, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic