answeredYes = (JOptionPane.showConfirmDialog(self,
"Are you Sure you want to do this",
"Confirm Action",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION);
And the Java application promptly hangs. When I press Ctrl-Break to
get a thread dump, one of the threads displayed is as shown below. It
appears that JOptionPane hangs waiting for its icon to load. This
hang occurs only when this is the first time a JOptionPane has been
displayed in the application. Otherwise there is no hang (because the
icon was already loaded?) I've also tried putting the JOptionPane
call inside an SwingUtilities.invokeAndWait() block, but still receive
the hang. Can someone tell me what would be causing this problem, or
at least a way around it? Thanks.
Bill Dennis
"Thread-10" prio=7 tid=0x16CFC0B8 nid=0xc34 in Object.wait()
[1740f000..1740fd8c
]
at java.lang.Object.wait(Native Method)
- waiting on <03F1CC78> (a java.awt.MediaTracker)
at java.awt.MediaTracker.waitForID(Unknown Source)
- locked <03F1CC78> (a java.awt.MediaTracker)
at javax.swing.ImageIcon.loadImage(Unknown Source)
- locked <03F1CC78> (a java.awt.MediaTracker)
at javax.swing.ImageIcon.<init>(Unknown Source)
at javax.swing.LookAndFeel$1.createValue(Unknown Source)
at javax.swing.UIDefaults.getFromHashtable(Unknown Source)
at javax.swing.UIDefaults.get(Unknown Source)
at javax.swing.MultiUIDefaults.get(Unknown Source)
at javax.swing.UIDefaults.getIcon(Unknown Source)
at javax.swing.UIManager.getIcon(Unknown Source)
at javax.swing.plaf.basic.BasicOptionPaneUI.getIconForType(Unknown
Sourc
e)
at javax.swing.plaf.basic.BasicOptionPaneUI.getIcon(Unknown
Source)
at javax.swing.plaf.basic.BasicOptionPaneUI.createMessageArea(Unknown
So
urce)
at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(Unknown
So
urce)
at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(Unknown
Source)
at javax.swing.JComponent.setUI(Unknown Source)
at javax.swing.JOptionPane.setUI(Unknown Source)
at javax.swing.JOptionPane.updateUI(Unknown Source)
at javax.swing.JOptionPane.<init>(Unknown Source)
at javax.swing.JOptionPane.showOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showConfirmDialog(Unknown Source)
at javax.swing.JOptionPane.showConfirmDialog(Unknown Source)
at javax.swing.JOptionPane.showConfirmDialog(Unknown Source)
at TestApp.doConfirm(TestApp.java:3301)
at TestButton.processAction(TestButton.java:551)
at TestButton$2.run(TestButton.java:168)
>It
>appears that JOptionPane hangs waiting for its icon to load.
I gather then you had better not use JOptionPane until "self's"
addNotify has completed. The alternative would be to feed it your own
predigested icons.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
new JOptionPane();
But I'd still like to know what the hang happens.
Bill Dennis
final myExtendedJLayeredPane self = this;
The reason for "self" was that in trying to solve this problem, I
tried putting the JOptionPane call inside of a
SwingUtilities.invokeAndWait(). But the JLayeredPane has already been
displayed for a quite a while by that point. So would its addNotify()
be called again just by my creating the "self" variable?
Bill Dennis
>. So would its addNotify()
>be called again just by my creating the "self" variable?
Sorry did not mean to imply that. I just wanted you to make sure
addNotify i.e. setVisible had been called. Otherwise Image loading
will likely fail.