Every thing is done twice

I have create an application with fewer buttonsWhen I clic on a button, the action of this button is done twice!!!E.g : clic on a "open button" launch 2 JFileChooser...Note that I'm working on Mac Os X.Thanks for helpBenoit
[273 byte] By [sechet_b] at [2007-9-27 14:35:38]
# 1
it is not so.even i am working in mac.my application is running perfectly but with fewer problem.Are you sure that for all action ,it is responding twice?.
geetha_er at 2007-7-5 22:35:04 > top of Java-index,Archived Forums,Swing...
# 2
maybe you added your actionListener twice
jensbruhn at 2007-7-5 22:35:04 > top of Java-index,Archived Forums,Swing...
# 3

my guess would be that you did something like this:

public class MyClass extends JPanel implements ActionListener() {

private JButton button;

public void actionPerformed( ActionEvent e ) {

System.out.println( "# 1" );

}

public static void main( String args[] ) {

button = new JButton( "Ok" );

button.addActionListener( this );

// ... lots of code here

button.addActionListener( new ActionListener() {

public void actionPerformed( ActionEvent e ) { System.out.println( "# 2" );

}

});

getContentPane().add( button );

}

}

Hmm.. but I think even that would just add the nested action listener.

Technique at 2007-7-5 22:35:04 > top of Java-index,Archived Forums,Swing...
# 4
Put a comment in the actionPerformed code to see what the source of the events are. This will let you know if your event is being done twice for the same object or whether you have two objects triggering the event.Garry.
edloveg at 2007-7-5 22:35:04 > top of Java-index,Archived Forums,Swing...
# 5
Yes , all is done twice.I'm programming under project Builder...ThanksBenoit
sechet_b at 2007-7-5 22:35:04 > top of Java-index,Archived Forums,Swing...
# 6
I have the same problem - I am also using JBuilder. Any ideas? Was this ever solved?
etchua1 at 2007-7-5 22:35:04 > top of Java-index,Archived Forums,Swing...
# 7

Normally this means that you have added an actionlistener twice or added an actionListener in another listener.

1. Adding an actionListener twice.myTextField.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

doStuff();

}

});

//... buncha other code ...

myTextField.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

doStuff();

}

});

In this case doStuff() will be called twice for each event.

2. Adding an ActionListener in another listener.myTextField.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

otherTextField.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

System.out.println("Hello");

}

}

}

}

In this case, each time the event fires on myTextField, another actionListener is added to otherTextField. So, the first time 'Hello' will print once, the next time twice, 3 times,...

bbritta at 2007-7-5 22:35:04 > top of Java-index,Archived Forums,Swing...