Object[] options = { "option 1", "option2",
"option 3" };
result = JOptionPane
.showOptionDialog(this,
"Welcome! ","Welcome Message",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options,
options[0]);
I Would like to show this JOptionPane after program is launched. But even if i do it at the end of constructor its invokes first before other components. Is there any way to do it?
It appears that you are calling this prior to the call to "setVisible(true)" on the rest of your application.
I would recommend you take a look at "SwingUtilities.invokeLater()"
to ensure that you code option pane is invoked at a "Later" time on the EDT.
If you're using Swing UIs, you can put the code inside windowOpened
event of the JFrame
or JDialog
.
public void windowOpened(java.awt.event.WindowEvent evt) {
// your JOptionPane
}
Then your JOptionPane will be shown after the Window becomes visible. I hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.