Skip to main content

Possible bug - AutoCompleteDecorator - cannot open system clipboard

7 replies [Last post]
voodooman2000
Offline
Joined: 2009-03-30
Points: 0

1) We have a Swing App which uses the AutoCompleteDecorator on a series of ComboBoxes.

2) In addition, the User may sometimes have MS Excel open and running a somewhat complex VB macro on Windows XP platform.

3) The User will run the Excel Macro then, while it's running, toggle over to the Swing App to make some modifications

4) When the User makes a selection on one of the ComboBoxes they will trigger the following stacktrace:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: cannot open system clipboard
at sun.awt.windows.WClipboard.openClipboard(Native Method)
at sun.awt.datatransfer.SunClipboard.getClipboardFormatsOpenClose(SunClipboard.java:315)
at sun.awt.datatransfer.SunClipboard.isDataFlavorAvailable(SunClipboard.java:175)
at org.jdesktop.application.TextActions.updateTextActions(TextActions.java:132)
at org.jdesktop.application.TextActions.access$400(TextActions.java:47)
at org.jdesktop.application.TextActions$ClipboardListener.flavorsChanged(TextActions.java:108)
at sun.awt.datatransfer.SunClipboard$1SunFlavorChangeNotifier.run(SunClipboard.java:427)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

5) When I comment out the AutoCompleteDecorator.decorate() line(s), the error goes away.

Is there a way for me to trap this exception or is it something that needs to be taken care of in the AutoCompleteDecorator?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

I think that the AutoCompleteDecorator is not the heart of the problem.

TextActions from the AppFramework determines whether the "paste" action is enabled by verifying that the clipboard contains a String-compatible data flavor. The problem is that the clipboard is not available when the combo box gains focus (and thereby causing the TextActions to determine paste eligibility).

The problem is that TextActions doesn't doesn't check whether the clipboard is available (no API method for doing so) or catch the exception when it's not.

You should file a bug with in the AppFramework tracker.

Karl

kschaefe
Offline
Joined: 2006-06-08
Points: 0

For clarification the [url=https://appframework.dev.java.net/issues/show_bug.cgi?id=65]bug[/url] was filed a while back.

Karl

voodooman2000
Offline
Joined: 2009-03-30
Points: 0

Thanks for the clarification. I'd seen that bug post a few days ago and was somewhat dismayed to hear that it's at the root of my bug. There does not appear to be any intention to fix the bug and in fact there seems to be some sort of dispute as tho whether or not it is in fact a bug. Some of the offerings I've seen for handling clipboard issue all seem to be using "sleep(50)" or better yet "sleep(200)" as the "solution". Oh well.

Of course if we were able to actually catch the Exception and handle it ourselves.......

kschaefe
Offline
Joined: 2006-06-08
Points: 0

I'm of the opinion that even though IllegalStateException is unchecked, it is documented and should (in this case) be legitimately handled with a catch block. Especially in the case of SAF, where an exception easily translates are "no data" and prevents the Paste action from enabling.

Karl

voodooman2000
Offline
Joined: 2009-03-30
Points: 0

Thanks for your help Karl. Do you suppose it will actually get "fixed" in the AppFrameWork?

kschaefe
Offline
Joined: 2006-06-08
Points: 0

I do think that AppFramework will catch the exception instead of passing it onto the user. None of the TextActions' ProxyActions are properly updated if the exception is thrown. I added some comments to the bug as well.

Karl

tl5
Offline
Joined: 2008-11-20
Points: 0

Since work on the Swing Application Framework has stopped at Version 1.03 the only fix for this problem is the use of the BetterSwingApplicationFramework (kenai.com/projects/bsaf/).

It is backwards compatible. Our program just worked after the replacement of the Jar.