• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPopupMenu - bug?

 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This works fine on my machine, unless I uncomment the JOptionPane line, in which case it throws an ArrayIndexOutOfBoundsException:

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
answered in cross-post in the forum.java.sun.com forums

Please read: Be Forthright When Cross Posting To Other Sites
[ May 26, 2008: Message edited by: pete stein ]
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so it is caused by a threading issue and can be solved by calling SwingUtilities.invokeLater. I just don't get how that can solve it. Isn't the call to JOptionPane.showMessageDialog called on the dispatch thread already? How can calling it on the dispatch thread, just a bit later, solve this?
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't the call to JOptionPane.showMessageDialog called on the dispatch thread already?


Seems like it would have to be, otherwise why would it prevent the collapsing of the menu?
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just beyond me... replace the call to JOptionPane.showMessageDialog with a Thread.sleep, and the exception goes away.


[ May 27, 2008: Message edited by: Wally Flint ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
OK, so it is caused by a threading issue and can be solved by calling SwingUtilities.invokeLater. I just don't get how that can solve it. Isn't the call to JOptionPane.showMessageDialog called on the dispatch thread already? How can calling it on the dispatch thread, just a bit later, solve this?


But SwingUtilities.invokeLater actually puts it as a new event into the event processing thread. I think this fixes it because the event that is currently processing (the closing of the JPopupMenu) is allowed to complete before showing the JOptionPane. You can see the popup menu close before the JOptionPane displays.
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to display an "OK" message while the JMenu popup menu was frozen in its open state. Also, it seems like there's a bug here because why should swing crash just because I blocked its thread for a few seconds?

Anyway, I've already decided not to pursue this anymore... but thanks for your help anyway.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!