Code Comments
Programming Forum and web based access to our favorite programming groups.Hi! Into my main class I Create JDialogs, and I use JDialog.DISPOSE_ON_CLOSE as defaultCloseOperation and setVisible(true) in order to show it. When I run my application for first time, and clicking on menu item I create a JDialog, so, I can use Toolbar buttons with no problems, actionPerformed is executed normally, just once, everything works OK. I close my Dialog and re- entering for second time begin problems. Toolbar buttons actionPerformed are executed twice, what happen?, this problem I noted, happens exactly when JDialog are loaded (created with new) for second time or more times. It is not supposed closing JDialog, will dispose every component content into it?, I tried using windowClosing event doing super.dispose(); and this.dispose(); but nothing at all. Is like closing JDialog it leave it hidden but not destroyed even using DISPOSE_ON_CLOSE. It is just only thing I guess actionPerformed on button events be dispatched twice, I don't know! I use jdk1.5.0_02 (update 2) Thanks
Post Follow-up to this messageIn your actionPerformed, do you check to see if the button is the source of the event?
Post Follow-up to this messageI'm adding JButtons on toolbar by for loop like this:
for (int i = 0; .....; i++) {
JButton myButton = new JButton(..);
myButton.addActionListener(this);
myButton.addActionCommand(String.Format("%d", i));
...
}
So you can Note I use actionCommand as Button ID. and...
public void actionPerformed(...e) {
if (((JButton)e.getSource).getActionCommand.equals("0") {
<instructions>
}
if (((JButton)e.getSource).getActionCommand.equals("1") {
<instructions>
}
..
}
when JDialog loas for first time (created using new) actionPerformed
dispatched well and instructions are executed OK. BUt exiting from JDialog
and re-entering againg actionPerformed are dispatched twice so,
instructions are executed twice.
Post Follow-up to this messageDoes your class have any static members? If your JButtons are stored static class members, this could result in the problem you are describing.
Post Follow-up to this messageNo! How I said buttons are dynamically created like as: JButton myButton = new JButton(); no static member. I just tried on windowClosing - JDialog, setVisible(false); and dispose(); but nothing happen, trying to destroy whatever dialog visible and hidden could have.
Post Follow-up to this messageAldemar Cuartas Carvajal via webservertalk.com wrote: > Hi! > > Into my main class I Create JDialogs, and I use JDialog.DISPOSE_ON_CLOSE as > defaultCloseOperation and setVisible(true) in order to show it. When I run > my application for first time, and clicking on menu item I create a > JDialog, so, I can use Toolbar buttons with no problems, actionPerformed is > executed normally, just once, everything works OK. I close my Dialog and re- > entering for second time begin problems. Toolbar buttons actionPerformed > are executed twice, what happen?, this problem I noted, happens exactly > when JDialog are loaded (created with new) for second time or more times. > It is not supposed closing JDialog, will dispose every component content > into it?, I tried using windowClosing event doing super.dispose(); and > this.dispose(); but nothing at all. Is like closing JDialog it leave it > hidden but not destroyed even using DISPOSE_ON_CLOSE. It is just only thing > I guess actionPerformed on button events be dispatched twice, I don't know! > > I use jdk1.5.0_02 (update 2) > > Thanks Are you adding an additional actionListener, so that two actions are performed for the one event? -- Nigel Wade, System Administrator, Space Plasma Physics Group, University of Leicester, Leicester, LE1 7RH, UK E-mail : nmw@ion.le.ac.uk Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
Post Follow-up to this messageNote that, although all Objects (eg windows and frames) are disposed on
closing, the Classes are not always. This would mean that any
information stored in static variables would remain in memory.
Are you creating the window in a static member variable? like this
class MyApp{
static JFrame myFrame = new MyFrame();
public static void main(String[] s){
myFrame.setVisible(true);
}
}
if so, your frame object may persist across different instatiations of
the app.
You could try using System.exit() when the application is closed. if it
is a static problem, this might fix it.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.