• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTABLE + JTEXTFIELD....  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • 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 !
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
 
Lon Allen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • 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).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!