How to catch cancel of editing in JTable?

Hi.
I have JTable and I'd like to do something (like to show some warning) when user cancel editing in table cell by pressing Esc key. I suppose, that this can be done with CellEditorListener and it's method cancelEditing(). But when I use this, after pressing Esc, cancelEditing is not called.
Should I use some other listener, or am I doing something wrong with CellEditorListener?
Thanks for reply.
The code I'm trying to use
import javax.swing.DefaultCellEditor;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.TableCellEditor;
public class TableTest extends JFrame implements CellEditorListener {
     private JTable table = null;
     public TableTest() {
          String[] headers = {"h1","h2"};
          String [][] data = {{"x","y"}, {"y", "z"}};
          table = new JTable(data, headers);
         TableCellEditor cellEditor = new DefaultCellEditor(new JTextField());
         cellEditor.addCellEditorListener(this);
         table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
          this.setContentPane(table);
     public static void main(String[] args) {
          TableTest frame = new TableTest();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);
     public void editingCanceled(ChangeEvent arg0) {
          System.out.println("Canceled");
     public void editingStopped(ChangeEvent arg0) {
          System.out.println("Stopped");
}

by default cancel of editing got catched by tab key, if u need the same with Esc key add the KeyListerner to u'r textfield u will find the solution. so i modified u'r code slightly, to get a solution.import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.DefaultCellEditor;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.TableCellEditor;
public class TableTest extends JFrame implements CellEditorListener {
     private JTable table = null;
     public TableTest() {
          String[] headers = {"h1","h2"};
          String [][] data = {{"x","y"}, {"y", "z"}};
          table = new JTable(data, headers);
          JTextField txtName = new JTextField();
          txtName.addKeyListener(new KeyAdapter(){
               public void keyPressed(KeyEvent e){
                    if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
                         System.out.println("Warning or error msg");
         TableCellEditor cellEditor = new DefaultCellEditor(txtName);
         cellEditor.addCellEditorListener(this);
         table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
          this.setContentPane(table);
     public static void main(String[] args) {
          TableTest frame = new TableTest();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);
     public void editingCanceled(ChangeEvent arg0) {
          System.out.println("Canceled");
     public void editingStopped(ChangeEvent arg0) {
          System.out.println("Stopped : ");
}

Similar Messages

  • How do I catch cancel dialogEvent from a popup?

    Guys and Gals,
    I was wondering about this myself and after doing a little googling and forum spelunking, thought I'd share what I came up with.
    Setup:
    <ol>Edit dialog inside of a popup. PopupCanceledListener and DialogListener defined</ol>
    Requirement:
    <ol>Need to catch cancel event to perform operation, most often a rollback</ol>
    Issues:
    <ol>By default, it does not appear that the "cancel" event triggers the dialog's dialogEventListener. Changing the dialog to yes/no has its own problems and so does inserting your own af:commandButtons. (TP4: ok/cancel dialogEvent - how to undo work?
    Proposed Solution:
    <ol>Record the state of the last dialog's event in a string. Compare that string's state to your PopupCanceledListener to perform an operation.</ol>
      private String dialog = "cancel";
      public void partDialogListener(DialogEvent dialogEvent)
        BindingContainer bindings = getBindings();
        if (dialogEvent.getOutcome().name().equals("ok"))
          dialog = "ok";
      public void onPartPopupCancelListener(PopupCanceledEvent popupCanceledEvent)
        if (dialog.equals("cancel"))
           // perform cancel operations
        dialog = "cancel";
      }Hope it helps someone out.

    Hi,
    the popup has a client side (JavaScript) cancel event
    http://download.oracle.com/docs/cd/E15523_01/apirefs.1111/e12419/tagdoc/af_popup.html
    Maybe this is a better option than setting a flag
    Frank

  • How to edit the JTable columns

    Hi all,
    please help me on this..
    I created one Jtable with 0-9 columns(10 columns)and
    I put only the 9th(last column) column is editable.
    the problem is if I enter any text message in 9th column
    and press another column then immediatly dissapears the
    9th column text...
    please tell me how to solve this problem .. because I want to take the
    9th column text to another Object....
    please send the solution anyone knows..
    public boolean isCellEditable(int row, int col){
    if(col == 9){
    return true;
    }else{
    return false;
    }

    If things go wrong while trying to edit table cells there is a good chance that you hit one of the many well known or even a new bug. These bugs are highly version dependent. So in any question please include the jdk version you are using and a very exact description of what you are seeing.
    Here I assume that by "press another column" you mean "click the mouse in the header region"?
    If so that's one of the well known, long-standing and not yet solved problems: jTable does cancel any edit on any notification from the columnModel - and due to suboptimal implementation of the tableHeaderUI even a single click does fire such a notification.
    There is some debate about how to handle the situation but no easy or totally satisfying approach - your best bet is to search the bug parade (and google) for partial solutions and their pros and cons.
    Greetings
    Jeanette

  • How can I get the edited value from the editor in JTable

    I have a JTextField added as an editor to a cell in JTable.
    I value gets changed when I press enter.
    but in actionPerformed of the JTextField when I say
    String txtEditorValue = txtEditor.getText();
    I am getting the old value. How can I get the edited value? Thanks.

    Hi,
    I guess, your understanding of how JTable works together with its models is not good enough - for example the method getTableCellEditorComponent(...) of the TableCellEditor interface is used to get the component, that should be used as editing component - its second parameter is a value that should be used to setup the editing component - it is normally not the editing component itself.
    JTable uses an underlying TableModel to store the cell values - if you have edited a cell, JTable gets the value of the editing component by itself and stores it in the TableModel using its setValueAt(...) method. To retrieve this data you only need to query the TableModel using row and column of this cell as parameters
    say jt is your JTable, and row and column are the row and column of the cell - so to get the value, simply use
    Object obj = jt.getModel().getValueAt(row,column);
    if you know, that there is a String in this cell use
    String str = (String) jt.getModel().getValueAt(row,column);
    The editor component is used for the view of the JTable - you only want the data, which is stored in the model - you don't have to deal with the GUI components in this case.
    greetings Marsian

  • How can i cancel my one year Creative Cloud Student and Teacher Edition?

    how can i cancel my one year Creative Cloud Student and Teacher Edition?

    when i click on customer support..
    i get this error

  • How to cancel all edits and go back to "as shot" ?

    hello All,
    I cleared all history, but somehow I am not back to my picture "as shot".
    How can I cancel everything I did, and start all over?
    thanks for reading,
    -Gian

    Gian wrote:
    I cleared all history, but somehow I am not back to my picture "as shot".
    Clearing the history steps only removes them from the panel. It doesn't actually "undo" what you did.
    How can I cancel everything I did, and start all over?
    Click on the "Reset" button at the bottom right of the Develop module panels.

  • HT201359 How do I cancel my subscription to the Guardian iPad edition

    How do I cancel my subscription to Guardian ipad edition

    There are instructions on this page for managing and stopping auto-renewing subscriptions : http://support.apple.com/kb/HT4098

  • How can i cancel my itunes account

    how can i cancel my itunes account and how can i make purchases using gift cards and not credit or debit cards?  it uses a credit card that i do not wish to use anymore.  i want to use only gift cards to make itunes purchases

    readerreed wrote:
    it uses a credit card that i do not wish to use anymore.  i want to use only gift cards to make itunes purchases
    Click "Account" under Quick Links at the top right of the iTunes store. Next to payment information click "Edit" and then select "None" under payment method.
    On an iOS device go to Settings>Store>Apple ID>View Apple ID>Payment Information>None.
    If "None" is not an option, you may want to contact iTunes support:
    http://www.apple.com/support/itunes/contact/

  • How can I cancel an Apple ID?

    I have 2 Apple ID's and would need to cancel one of them because it is incorrect. My App Store automatically uses the incorrect one and I need it uses the correct one so how can I cancel an incorrect Apple ID?

    You can't.   Just use the one you favour from now on and the other will fade gracefully away.   But remember, updates to purchases you have made will still require you to use the original details.   You will need to edit the details on App store so that only your preferred ID shows up.

  • How do I cancel my Verizon contract online

    Hi,
    I have found that even though you can subscribe online, I can't cancel online? What? So I have to wait and listen to Verizon support while they try to convince me to stay? So this is what being customer friendly means in Verizon, right? 
    I wanted to contact via email. Of course there is no email. But this is expected from a company that asked me to "fax" my documents in 2012 (and funnily this is for "security reasons". yeah right). I expected to find a fax number in the support page.
    Look at other support options. If you want to get support for "My Account, Plan or Bill" or "My Device" Verizon doesn't care about you (you are a problem to them) so all the agents are always busy. But if you want to get help about "Shopping Verizon Wireless" they are always available. And the funny thing is there is no queue system even though this is an online chat system; so you have to come back and check repeatedly. It doesn't even give a time estimation. I smell something fishy here. (To convince people to give up. Don't contact support.)
    Ah and there is the social support. They are exactly like forums but with more advertisement (aka spam). I am sorry, I meant only advertisement. But instead of being honest we call them "Social support". Can you honestly say this page is about support https://plus.google.com/+verizon/posts or https://www.facebook.com/verizon . Or are they mainly about spamming and support is only used to increase the follower numbers?
    So how do I cancel online? Please tell me there is no way to cancel online so I would learn not to have any business with Verizon (wireless or otherwise) in the future.
    Thank you.

    I am overseas - and your phone does not work here, and there are no Verizon stores here - so how the happy (removed) do I cancel service for a phone I cant use, that doesn't work, from a carrier that is non present ?  ie - I need to cancel the phone online - or y'all might want upgrade your global services......
    Comment edited as required by the Terms of Service.
    Message was edited by: Admin Moderator

  • How to stop/cancel Process Chain in BI 7.0

    Hi,
    Could you tell me how to stop/cancel a process chain that hangs with status yellow or green in BI 7.0? There was an easy option to do it in 3.x, but I cannot find a similar option in 7.0.
    What happens is that at random our process chains hang at a certain variant with either yellow or even green status and do not proceed further. What happens is that in a couple of hours another pchain run occurs and it executes fine. Then again at random (might be the same day or the next day) the process chain hangs again. I think that all those "hanged" pchains pile up in the queue, so that it cause other future pchains to hang as well at some point. So, is there anyway to stop/cancel these zombie process chains when it stops at a particular event RSPROCESS in BI 7?
    Thank you,
    AG
    Message was edited by:
            AG

    Hi Frank,
    Thanks for your reply. I have a few questions.
    1)SM37 -->Kill Job
    We cannot do that because the job has already finished.
    2)SM50/sm66- ->Kill process
    There are no hanged processes to kill
    3)RSPC>Job Log>Make the process RED forecefully
    How do you do that exactly?
    4)RSPC>Process chain> main Menu"Remove from Scheduling"  OR
    5)se37-->RSPC_API_CHAIN_INTERRUPT
    give RFC BW system name(technical) and process chain name(technical) - we can do this,  but what exactly would it accomplish. Would it remove the process chain from any runs in the future or also any hanged ones in the past? An how is this step different from #4?
    Thank you,
    AG

  • How do I cancel a download that won't go through....it's waiting

    I am trying download music.....there is a problem with my credit card so it won't download...it is in a holding pattern trying to download.  My laptop downloaded the music and used the same credit card.  My iPad just won't give up.  How do I cancel...edit doesn't work.

    On the iPad, tapping the icon functions the same as pause/resume

  • How to catch the error occurred in Integration Process, and then save it?

    1. how to catch the error occurred in Integration Process, and then save the detailed error message to the file?
    2. there are fault message type for inbound message interface, how to use the fault message type in IR?
    Thanks,
    Michael
    Message was edited by: Spring Tang
    inital
    Message was edited by: Spring Tang
    detailed message output
    Message was edited by: Spring Tang
    fault message type

    Hi Spring,
    If u give an exception step along with your Transformation Step, whenever some error occurs in your message mapping, this exception block wil be triggered.
    You can configure your exception block to do all exception processing that you want. This exception handling is like any other java Exceptio n Handler. You can do anything that you want in your exception handler block on the basis of your requirements.
    <i>If an exception is triggered at runtime, the system first searches for the relevant exception handler in surrounding blocks. If it does not find the correct exception handler, it continues the search in the next block in the block hierarchy.
    When the system finds the correct system handler, it stops all active steps in the block in which the exception handler is defined and then continues processing in the exception handler branch. Once the exception handler has finished processing, the process is continued after the block.
    If the system fails to find an exception handler, it terminates the integration process with an error.</i>
    Regards,
    Bhavesh

  • How can I cancel ?

    Hello ~
    I was purchases before 3 month by ITUNES (monkey3) music downloads.
    But I don't want to no more extension music download .
    How can I cancel to automatically music downloads ?
    If you want to any information about this case 
    Auto extension date of 06 Dec
    Thank you for your help .
    <Email Edited by Host>

    If you purchased the upgrade in the last 15 days, contact the Apple online store at the number shown at the bottom of this page and request a refund.

  • Edit a JTable cell, click save button, value isn't stored in JTable

    I'm editing a JTable cell, just using default editor provided by JTable
    I click a save button elsewhere in my GUI
    The value typed into the cell so far isn't stored in the TableModel yet and so doesn't get saved.
    How can I make sure the value gets stored in the JTable in the above scenario when the JButton is pressed but before saving.
    Preferably I'd like the code with the JButton not to have to know about the JTable at all.
    Cheers,
    D

    I the forums 100s of times.Many thanks. If they had a decent search on this forum I might have found it as I did try.
    Come to think of it - Sun have completely fcukd up this forum.

Maybe you are looking for