0

i have created a static instance of a generic dialog in my program

static GenericDialog SaveDialog = null;

and below is the code to display the dialog

public boolean DispSaveDialog()
{
    //gd.addStringField("Identity : ", "annot");
    if(SaveDialog == null)
    {
        SaveDialog =  new GenericDialog("Save");
        Panel idnPanel = new Panel();
        idnPanel.add(new Label("Identity"));
        idnTextComp = new TextField("annot");
        csPrefix = idnTextComp.getText();
        TextListener tl = new TextListener() {

            @Override
            public void textValueChanged(TextEvent e) {
                // TODO Auto-generated method stub
                csPrefix = idnTextComp.getText();
            }
        };
        idnTextComp.addTextListener(tl);
        idnPanel.add(idnTextComp);
        SaveDialog.addPanel(idnPanel);
        final TextComponent textComponent = new TextField();
        ActionListener al = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                String label = e.getActionCommand();                
                //csPrefix = gd.getNextString();
                if (label=="Browse")
                {                   
                    String csFilename = imp.getTitle();                 
                    csTextFileName = FileNameProcess( csFilename );     
                }   
                textComponent.setText(csTextFileName);
            }
        };
        Button btBrowse = new Button("Browse");
        btBrowse.addActionListener(al);     
        Panel panel = new Panel();

        panel.add(new Label("Folder : "));
        //textComponent.setBounds(gd.getBounds());
        panel.add(textComponent);
        panel.add( btBrowse );  
        SaveDialog.addPanel(panel);         
    }   
    SaveDialog.showDialog();
    return true;
}

the issue i am facing is, when i open the dialog the second time, the OK and Cancel events are not triggered. i have a feeling that the issue is silly, sorry and thanks in advance.

Preethi
  • 154
  • 14
  • The problem is that most probably the listeners are still being linked to the first instance of GenericDialog and not with the new instance. Have you tried debugging the program to check with which object are the listeners being bound to the second time around – Brendan Cutajar Jun 06 '12 at 06:15
  • this is a plugin developed for imageJ. so i cant debug the same. i tried displaying strings, but i cant seem to understand the behaviour – Preethi Jun 06 '12 at 06:37
  • Did you try if the problem stays the same after you removed the static part from your variable? – Thihara Jun 06 '12 at 09:51
  • i use the variable at other parts of the code and hence should be static. – Preethi Jun 07 '12 at 03:56

1 Answers1

0

The above code was so that when the generic dialog was displayed the second time the old values would be retained.. i did a workaround for the same where i save the strings entered the first time in static string variables and load them after checking for null values.

this is not the solution, just a workaround so i could close the issue on time. :(

Preethi
  • 154
  • 14