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 / General / January 2006

Tip: Looking for answers? Try searching our database.

JTable InputVerifier

Thread view: 
Big Jim - 23 Jan 2006 19:41 GMT
Hi,

I'm using a JFormattedTextField as the editor for a JTable column and have
added an InputVerifier to do validation. Even though the
InputVerifier.verify method returns false it still allows the cell to lose
focus simply returning the cell to the last valid value (the
JFormattedTextField standard behaviour).

Anyone know what's going onthere? (java 1.5)

Cheers, Richard.
zero - 23 Jan 2006 20:01 GMT
> Hi,
>
[quoted text clipped - 7 lines]
>
> Cheers, Richard.

Like you said, that is the standard behaviour.
Create a new TableCellEditor (make your life easier, and use
DefaultCellEditor) that doesn't call stopCellEditing and cancelCellEditing
unless the value is valid.
Big Jim - 23 Jan 2006 20:09 GMT
Cheers, I'll do that.

just out of interest, is that the usual way to do this or a workaround?
I had thought that attaching an InputVerifier to a component (which I
believe a table cell is) was a perfectly viable way to verfiy input and hold
the focus until a valid input is supplied e.g. I can use this method
successfully on a JTextField or JFormattedTextField as long as it isn't in a
JTable.

>> Hi,
>>
[quoted text clipped - 12 lines]
> DefaultCellEditor) that doesn't call stopCellEditing and cancelCellEditing
> unless the value is valid.
zero - 23 Jan 2006 20:15 GMT
> Cheers, I'll do that.
>
[quoted text clipped - 4 lines]
> e.g. I can use this method successfully on a JTextField or
> JFormattedTextField as long as it isn't in a JTable.

I've never used a JFormattedTextField, but I've heard they're trouble.  So,
I stay away from them.  It's easy enough to implement custom listeners that
verify input.
Thomas Hawtin - 23 Jan 2006 20:32 GMT
> I've never used a JFormattedTextField, but I've heard they're trouble.  So,
> I stay away from them.  It's easy enough to implement custom listeners that
> verify input.

Difficult to get right and fiddly. Using a custom Document, or better a
DocumentFilter is better and much easier.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Big Jim - 23 Jan 2006 20:34 GMT
>> Cheers, I'll do that.
>>
[quoted text clipped - 10 lines]
> that
> verify input.

Implemented the stopCellEditing as you suggested, works great, Cheers again.


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.