swing - Java return from a ShowOptionDialog from an inner JPanel -


i used

 joptionpane.showoptiondialog(null,          new mypanel(),          "import",          joptionpane.default_option,          joptionpane.plain_message,         null, new object[]{}, null); 

because don't want default buttons provided optiondialog , created buttons inside mypanel extends jpanel problem how can close optiondialog inside mypanel fired actionevent? don't care return value, long dialog disappears. , realize might not best design i've been working on lot of times i'd prefer fix involves little change in structure possible. thanks!

convert joptionpane jdialog, using joptionpane.createdialog(string title) :

joptionpane optionpane = new joptionpane(getpanel(),                         joptionpane.plain_message,                         joptionpane.default_option,                          null,                         new object[]{}, null); dialog = optionpane.createdialog("import"); dialog.setvisible(true); 

now inside actionperformed(actionevent ae) method, write :

dialog.dispose(); 

have @ working example :

import java.awt.*; import java.awt.event.*; import java.io.ioexception; import java.net.malformedurlexception; import java.net.url; import javax.swing.*; import javax.imageio.imageio;  public class joptionpaneexample {     private jdialog dialog;      private void displaygui()     {         joptionpane optionpane = new joptionpane(getpanel(),                         joptionpane.plain_message,                         joptionpane.default_option,                          null,                         new object[]{}, null);         dialog = optionpane.createdialog("import");         dialog.setvisible(true);     }      private jpanel getpanel()     {         jpanel panel = new jpanel();         jlabel label = new jlabel("java technology dive log");         imageicon image = null;         try         {             image = new imageicon(imageio.read(                     new url("http://i.imgur.com/6mbhzru.png")));         }         catch(malformedurlexception mue)         {             mue.printstacktrace();         }         catch(ioexception ioe)         {             ioe.printstacktrace();         }          label.seticon(image);          jbutton button = new jbutton("exit");         button.addactionlistener(new actionlistener()         {             @override             public void actionperformed(actionevent ae)             {                 dialog.dispose();             }         });          panel.add(label);         panel.add(button);          return panel;     }     public static void main(string[] args)     {         swingutilities.invokelater(new runnable()         {             public void run()             {                 new joptionpaneexample().displaygui();             }         });     } } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -