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 / May 2007

Tip: Looking for answers? Try searching our database.

JTable Editing not take effect until hit Enter

Thread view: 
RC - 24 May 2007 16:18 GMT
Hello dudes,

I found out if you editing a JTable cell without hit
the Enter or Tab key. Then the new cell value won't take
effect. For example, a table cell value is "abc" and
you change it to "xyz". Then when you read that table
cell value, it still "abc". You MUST hit the Enter or
Tab key, then you will get that table cell value as "xyz".

How can I force that table cell value as "xyz" WITHOUT
hit the Enter or Tab key?

Thank Q very much in advance!
Thomas Fritsch - 24 May 2007 17:23 GMT
> I found out if you editing a JTable cell without hit
> the Enter or Tab key. Then the new cell value won't take
> effect. For example, a table cell value is "abc" and
> you change it to "xyz".
The problem is, that in this case the cell editor's stopCellEditing()
method is not called. See also the API doc of CellEditor#stopCellEditing()

> Then when you read that table
> cell value, it still "abc". You MUST hit the Enter or
> Tab key, then you will get that table cell value as "xyz".
>
> How can I force that table cell value as "xyz" WITHOUT
> hit the Enter or Tab key?
You have to call your cell editor's stopCellEditing() method at appropriate
times (probably when the cell looses keyboard focus):
  JTable yourTable = ...;
  if (yourTable.isEditing())
    yourTable.getCellEditor().stopCellEditing();

Or simpler: somewhere at the beginning you tell your JTable to do those
stopCellEditing calls automatically for you:
  yourTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

Signature

Thomas

Steve W. Jackson - 24 May 2007 22:04 GMT
> > I found out if you editing a JTable cell without hit
> > the Enter or Tab key. Then the new cell value won't take
[quoted text clipped - 18 lines]
> stopCellEditing calls automatically for you:
>    yourTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

I'm pretty sure that the default behavior does this already (though I
could be mistaken).  The OP's description sounds like he's trying to do
it without a focus change or edit completion event.  Or maybe he's
expecting the edit to get accepted when closing the containing dialog or
frame, which does not happen.  The default behavior there is to cancel
the edit and discard it.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Richard Reynolds - 26 May 2007 13:26 GMT
>> > I found out if you editing a JTable cell without hit
>> > the Enter or Tab key. Then the new cell value won't take
[quoted text clipped - 29 lines]
>
> = Steve =

Maybe he could write a CaretListener and update the value each time the
cell's field is updated? I vaguely remember having to do something like
this, I think JFormattedTextFields were involved too.


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.