Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

JPopupMenu - bug?

 
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:

 
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 ]
 
Sheriff
Posts: 22015
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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 ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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.
 
What's a year in metric? Do you know this metric stuff tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic