java - JDialog not centered over parent JFrame -
i trying jdialog popup in center of jframe on button click. have joptionpanel popup correctly on parent jframe, jdialog popping relative jframe not in center.
the buttons jmenuitem in code, wrote them here jbutton make things easier , straight forward.
here's code:
call parent jframe:
jbutton = new jbutton("about"); about.addactionlistener(new actionlistener() { //this 1 not in center of myjframe public void actionperformed(actionevent e) { new aboutdialog(myjframe.this); } }); jbutton exit = new jbutton("exit"); exit.addactionlistener(new actionlistener() { //this 1 in center of myjframe public void actionperformed(actionevent e) { if(joptionpane.showconfirmdialog(myjframe.this, "are sure want exit ?","",joptionpane.yes_no_option) == 0) system.exit(0); } });
aboutdialog class
public class aboutdialog extends jdialog{ public aboutdialog(jframe parent) { setlocationrelativeto(parent); setlayout(new borderlayout()); ...
thank you
setlocationrelativeto(parent);
the above code needs executed after have added components dialog , packed dialog , before make dialog visible.
in current code size of dialog (0, 0) can't centered properly.
Comments
Post a Comment