Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

How do I limit input in a JTable cell to integers only?

Thread view: 
Dag Sunde - 29 Mar 2004 10:16 GMT
I have a 4 column JTable, and in the last 3 columns I
want the input to be limited to the keys "0" to "9"
only.

I want it to not react on any other keys at all while
editing.

anyone?

TIA...

--
Dag.
Rob Jones - 29 Mar 2004 13:21 GMT
> I have a 4 column JTable, and in the last 3 columns I
> want the input to be limited to the keys "0" to "9"
[quoted text clipped - 9 lines]
> --
> Dag.

You will need to subclass the editor for those fields.
Possible to do in Editor class or make the give the
underlying textfield a custom document.

The following text comes from now out of date swing tutorial.
I cant see it in the latest versino from sun but this might
help a bit.
------------
The data in a change-validated field is checked each time the field
changes. A field that is change-validated can never contain invalid data
because every change (keystroke, cut, copy, and so on) that might cause
the data to be invalid is rejected. To create a change-validated text
field you need to provide a custom document for your text field. If you
aren't familiar with documents yet, see Concepts: About Documents.

    Warning:  Do not use a document listener for change validation. By
the time a document listener has been notified of a change, it's too
late, the change has already taken place. See the last couple of
paragraphs in Listening for Changes on a Document for more information.
------------
Babu Kalakrishnan - 29 Mar 2004 13:37 GMT
> I have a 4 column JTable, and in the last 3 columns I
> want the input to be limited to the keys "0" to "9"
[quoted text clipped - 4 lines]
>
> anyone?

Buid a custom editor with the desired behaiour and set it as the
CellEditor for those columns.

BK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.