jdialog - Listener not working with Modal Dialog -
my intention - create frame, add button. when clicked button, modal dialog appears custom buttons , text fields. takes user input dialog. close dialog , pass value frame controls.
question - achieved when created modeless dialog, not work modal dialog:
when used, modeless dialog, clicking ok button on dialog, passed value frame , closed dialog. when set dialog modal = true, ok button on dialog not working
code used:
jbutton diabtn = new jbutton("dialog"); diabtn.addactionlistener(new actionlistener(){ public void actionperformed(actionevent ae){ final jdialog dialog = new jdialog((jframe)null,"dia window",true); dialog.setdefaultcloseoperation(jdialog.dispose_on_close); dialog.setsize(350,200); jlabel dialbl1 = new jlabel("enter name"); jbutton diaok = new jbutton("ok"); final jtextfield diatxt = new jtextfield(20); diaok.setsize(60,60); dialog.setlayout(new flowlayout()); dialog.add(dialbl1); dialog.add(diatxt); dialog.add(diaok); dialog.setvisible(true); // adding listener button on dialog diaok.addactionlistener(new actionlistener(){ public void actionperformed(actionevent ae){ string tempval = diatxt.gettext(); lbldialogvalue.settext(tempval); dialog.dispose(); } }); } });
i'm no java expert, there corroboration saying: code after .setvisible()
executed after dialog closed. see reference.
Comments
Post a Comment