Redifining/replacing an ActionListener for a JButton doesn't work

Hello,

I am trying to replace a JButton's ActionListener inside another JButton's ActionListener, but is doesn't seem to work. Here's what I did :

editButton =new JButton(EDIT_BUTTON_TEXT);

editButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent event){

//

// Change the Add button's text to "OK" and

// redefine it's action listener

//

addButton.setText(OK_BUTTON_TEXT);

final ActionListener savedAddBtnActionListener = addButton.getActionListeners()[0];

addButton.removeActionListener(savedAddBtnActionListener);

addButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent event){

...

...

}

});

}

});

It doesn't change the buttons Text, I posted something similar in a previous post, and the addButton's new ActionListener doesn't work. I tried to print something in the console inside of it to test but nothing is outputted.

Any Ideas anyone?

Thank you,

Gabriel

[1687 byte] By [rossettigaba] at [2007-10-3 3:30:39]
# 1
I figured it out thanks to my other thread, I was resetting the values at the wrong moment, so I never got to use my new action listener... I need a teddy bear.... That's what you get for working late....
rossettigaba at 2007-7-14 21:24:34 > top of Java-index,Desktop,Core GUI APIs...
# 2
In general, you can't use the [0] on the returned array, since you can never know what listeners might be added by Swing / LAF layers. Just store a pointer to your old action listener somewhere and retrieve it later if necessary. The same goes for all other types of listeners.
kirillga at 2007-7-14 21:24:34 > top of Java-index,Desktop,Core GUI APIs...