JTable Editing not take effect until hit Enter

Discussion in 'Java' started by RC, May 24, 2007.

  1. RC

    RC Guest

    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!
     
    RC, May 24, 2007
    #1
    1. Advertising

  2. 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);

    --
    Thomas
     
    Thomas Fritsch, May 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Curt_C [MVP]

    Default button when hit Enter

    Curt_C [MVP], Jan 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    361
    Harry
    Jan 13, 2004
  2. kai
    Replies:
    9
    Views:
    740
  3. CK
    Replies:
    9
    Views:
    400
    Jerry Rasmussen
    Oct 19, 2006
  4. Jimmy

    Why #pragma pack not take effect?

    Jimmy, Jul 3, 2007, in forum: C Programming
    Replies:
    5
    Views:
    773
    Kenny McCormack
    Jul 4, 2007
  5. HopfZ
    Replies:
    0
    Views:
    576
    HopfZ
    Aug 28, 2006
Loading...

Share This Page