Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JOptionPane Hangs

59 views
Skip to first unread message

Bill Dennis

unread,
Jul 15, 2003, 12:42:00 AM7/15/03
to
I display a JOptionPane as follows (the program is not in the
EventDispatchThread at the time; a JButton's actionPerformed() method
has started a new Thread):

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)

Roedy Green

unread,
Jul 15, 2003, 3:40:33 AM7/15/03
to
On 14 Jul 2003 21:42:00 -0700, wjde...@rmi.net (Bill Dennis) wrote or
quoted :

>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.

Bill Dennis

unread,
Jul 15, 2003, 8:23:07 AM7/15/03
to
I think I was able to circumvent the problem by putting the following
at the very start of the application:

new JOptionPane();

But I'd still like to know what the hang happens.

Bill Dennis

Bill Dennis

unread,
Jul 15, 2003, 10:31:52 AM7/15/03
to
Roedy, I'm not sure I understand your answer. Just before the call to
create the JOptionPane, I issued the following:

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

Roedy Green

unread,
Jul 15, 2003, 7:48:20 PM7/15/03
to
On 15 Jul 2003 07:31:52 -0700, wjde...@rmi.net (Bill Dennis) wrote or
quoted :

>. 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.

0 new messages