-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.5
-
sparc
-
solaris_2.5.1
Name: rm29839 Date: 12/10/97
The code below runs fine on NT and on Solaris
2.5.1 using green threads. Running with native
threads it hangs. The problem involves trying
to access the clipboard from the awt thread.
If I remove the call to "canPaste()" from
"MyMenu.show()", it works. However, I need
that call there as you can see.
Steve Buroff
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
class Popup extends TextArea implements ClipboardOwner {
static final Clipboard clipboard =Toolkit.getDefaultToolkit().getSystemClipboard();
PopupMenumenu;
Popup() {
super("", 20, 60);
menu = new MyMenu();
add(menu);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
public void
processMouseEvent(MouseEvent event) {
if(event.isPopupTrigger()){
menu.show(event.getComponent(), event.getX(), event.getY());
event.consume();
}
super.processMouseEvent(event);
}
boolean
canPaste() {
Transferable data;
data = clipboard.getContents(this);
try {
data.getTransferData(DataFlavor.stringFlavor);
return true;
}
catch(Exception excp) {
return false;
}
}
public void
lostOwnership(Clipboard cb, Transferable tr) {
}
public static void
main(String[] args) {
Frame frame;
Popup popup;
frame = new Frame("Native Threads Bug");
popup = new Popup();
frame.add(popup, "Center");
frame.pack();
frame.setVisible(true);
}
class MyMenu extends PopupMenu {
MenuItem item;
MyMenu() {
item = new MenuItem("paste");
add(item);
add(new MenuItem("always enabled"));
}
public void
show(Component comp, int xLoc, int yLoc) {
item.setEnabled(canPaste());
super.show(comp, xLoc, yLoc);
}
}
}
(Review ID: 21715)
======================================================================
- duplicates
-
JDK-4182518 Race condition with clipboard modal waits
-
- Closed
-