swing - Move JOptionPane's showConfirmDialog along with Java Application -


i want have warning showconfirmdialog window in front of application if gui moves different position, works fine if don't move application , press 'close alt+x' button, if move application second screen warning showconfirmdialog window stays @ old position, how move warning window along gui, please give me directions, thanks.

close alt+x button

        //close window button     jbutton btnclosewindow = new jbutton("close alt+x");     btnclosewindow.setmnemonic('x');     btnclosewindow.addactionlistener(new actionlistener() {         public void actionperformed(actionevent e) {             jframe frame = new jframe();              int result = joptionpane.showconfirmdialog(frame, "are sure want close application?", "please confirm",joptionpane.yes_no_option);             //find position of gui , set value             //dialog.setlocation(10, 20);             if (result == joptionpane.yes_option)                 system.exit(0);         }     }); 

so far tried set position centre of location of gui showconfirmdialog, didn't work.

the joptionpane should position relative parent window. since you're using newly created , non-displayed jframe dialog's parent window, dialog knows center in screen.

so key here not use old jframe parent window, rather use your displayed jframe or 1 of displayed components parent component, first parameter of joptionpane.showconfirmdialog method call.

so if make jbutton final , pass method call?

// **** make final final jbutton btnclosewindow = new jbutton("close alt+x"); // ***  // ....  btnclosewindow.addactionlistener(new actionlistener() {     public void actionperformed(actionevent e) {          // jframe frame = new jframe();  // **** rid of ****          // ***** note change? we're using btnclosewindow first param.         int result = joptionpane.showconfirmdialog(btnclosewindow ,                "are sure want close application?",                "please confirm",joptionpane.yes_no_option);          // ...... 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -