Re: JTable Editing not take effect until hit Enter




"Steve W. Jackson" <stevewjackson@xxxxxxxxxxx> wrote in message
news:stevewjackson-AA21FB.16043624052007@xxxxxxxxxxxxxxxxx
In article <newscache$f70kij$iib$1@xxxxxxxxxxx>,
Thomas Fritsch <i.dont.like.spam@xxxxxxxxxxx> wrote:

RC wrote:
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);

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 =
--
Steve W. Jackson
Montgomery, Alabama

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.


.



Relevant Pages

  • Re: How do I get a 2nd & 3rd page of the same label? Say an Avery
    ... MVP Microsoft [Publisher] ... cell, hit the tab key. ... (Some labels aren't as easy as this.) ...
    (microsoft.public.word.docmanagement)
  • Re: Tab key
    ... > press the tab key twice! ... move the active cell one to the right after activating a cell in ... the column to be skipped over, or to move the active cell two cells to ...
    (microsoft.public.excel)
  • Intercepting a Tab on Entry
    ... I'm using ActiveCell to make determination of certain actions to take ... What I've discovered is that if the user makes an entry into a cell ... and hits the Tab key rather than the Enter key, ...
    (microsoft.public.excel.programming)
  • Re: Problem tabbing to enter data in table
    ... navigate from cell to cell, if I don't press the tab key firmly and ... most often when the first letter the first letter of the table cell is ... I call it a "partial" response, ... because hitting the tab key a second produces the correct capital ...
    (microsoft.public.word.tables)
  • Re: TAB key appends new row to table - can this be turned off
    ... Dim oCell As Cell ... When you're in the last cell of a table, the TAB key appends a new ... Is there a way to instruct Word, using a macro, to move to ... >I know that there are VBA functions that tell you what row and column ...
    (microsoft.public.word.tables)