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 / February 2006

Tip: Looking for answers? Try searching our database.

jtable events

Thread view: 
Big Jim - 07 Feb 2006 20:06 GMT
Hi, I've a JTable where the first column contains an extension of a
JFormattedTextField.

The field is set to only allow the user to type in dates in the format
MM/DD/YYYY i.e. a blank field is displayed as __/__/____, when the user
types it replaces the characters where the underscores are and skips over
the / chars.

This works fine if I double click on the cell and start typing. It also
works fine as a straightforward text field if I select the field or tab onto
the field and start typing.

If I tab onto the cell in the JTable (either from the component before the
JTable or from another cell within it) and start typing, the first character
gets entered into the field before any of the text field verification kicks
in i.e. the key event doesn't seem to get sent to the processKey method in
the text field for verification allowing the field to become 11 chars long
which then screws up further validation.

I've tried various methods of capturing the focus or key events from the
JTable and passing them to the textfield, trying to make the cell go into
editiing mode when it's tabbed onto, altering JTable config such as
setSurrendersFocus etc. but just can't seem to get the combination right.

Anyone know what I should be aiming for here?

Cheers, Richard.
zero - 10 Feb 2006 13:01 GMT
> Hi, I've a JTable where the first column contains an extension of a
> JFormattedTextField.
[quoted text clipped - 24 lines]
>
> Cheers, Richard.

How did you set the JFormattedTextField as editor?  The default
implementation brings up the editor when you double click, as you say.  
I also believe (can't test it right now though) that the cell enters
editing mode when you start typing while the cell has focus.  So
basically, it has very little to do with getting the focus, and it will
be hard to fix by only handling focus events.

You have different options availalbe: don't start the editor when you
type in the cell (only editing it after double clicking), start the
editor as soon as the cell has focus, or try to emulate the default
behaviour.

The first option can be set (again, can't test right now) by using
JComponent:putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);

For the second option, you could try adding a ListSelectionListener to
JTable:getSelectionModel().  Then when capturing
ListSelectionListener:valueChanged(), call JTable:editCellAt()

The third option may require overriding JTable:processKeyBinding(), but
I'm not sure how you would go about that.


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.