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

Java pop-up error message

2 views
Skip to first unread message

Al Murphy

unread,
Feb 12, 2004, 8:25:11 AM2/12/04
to
Folks,

Interesting one here. I've implemented a right mouse click popup
menu thingy that I found somewhere (code included below).
It works perfectly using the appletviewer but when I view it in
IE6.0 & NN7.1 I get the following error message
"java.security.AccessControlException: access denied
(java.awt.AWTPermission accessClipboard)":
Would appreciate you comments...


****** ERROR MESSAGE AS FOLLOWS *******

Java(TM) Plug-in: Version 1.4.2_03
Using JRE version 1.4.2_03 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\amurphy

Proxy Configuration: Browser Proxy Configuration

----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
p: reload proxy configuration
q: hide console
r: reload policy configuration
s: dump system properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
java.security.AccessControlException: access denied
(java.awt.AWTPermission accessClipboard)

at java.security.AccessControlContext.checkPermission(Unknown Source)

at java.security.AccessController.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkSystemClipboardAccess(Unknown
Source)

at sun.awt.windows.WToolkit.getSystemClipboard(Unknown Source)

at PopupMenuMouseListener.mouseClicked(PopupMenuMouseListener.java:142)

at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

java.security.AccessControlException: access denied
(java.awt.AWTPermission accessClipboard)

at java.security.AccessControlContext.checkPermission(Unknown Source)

at java.security.AccessController.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkSystemClipboardAccess(Unknown
Source)

at sun.awt.windows.WToolkit.getSystemClipboard(Unknown Source)

at PopupMenuMouseListener.mouseClicked(PopupMenuMouseListener.java:142)

at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

****** END ERROR MESSAGE ******

CODE AS FOLLOWS:

public class Widgets extends JApplet
{
int appletWidth, appletHeight;
JPanel P1;
JTextField jtfInput;
JTextArea jtaOutput;

PopupMenuMouseListener pmml = new PopupMenuMouseListener();


public void init()
{
// Physical dimensions of the applet
Dimension d = getSize();
appletWidth = d.width;
appletHeight = d.height;

// Colors of the applet
getContentPane().setBackground(Color.black);
getContentPane().setForeground(Color.white);

getContentPane().setLayout(new BorderLayout());


P1 = new JPanel();
jtfInput = new JTextField(10);
jtfInput.addMouseListener(pmml);
jtaOutput = new JTextArea(10, 10);
jtaOutput.addMouseListener(pmml);
P1.add(jtfInput);
P1.add(jtaOutput);

getContentPane().add(P1, BorderLayout.CENTER);


} // end init()

**** END CODE ******

**** POPUP CODE ****


import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import javax.swing.*;
//import javax.swing.event.*;
import javax.swing.text.*;

public class PopupMenuMouseListener extends MouseAdapter
{
private JPopupMenu popup = new JPopupMenu();

private JMenuItem undoItem, cutItem, copyItem, pasteItem,
deleteItem, selectAllItem;
private JTextComponent textComponent;
String savedstring="";
String lastactionselected="";


public PopupMenuMouseListener()
{
Action action = new AbstractAction("Undo")
{
public void actionPerformed(ActionEvent ae)
{
if(lastactionselected.compareTo("")!=0)
{
textComponent.setText("");
textComponent.replaceSelection(savedstring);
}
}
};

undoItem = popup.add(action);
undoItem.setMnemonic('t');
popup.addSeparator();
action = new AbstractAction("Cut")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="c";
savedstring=textComponent.getText();
textComponent.cut();
}
};

cutItem = popup.add(action);
cutItem.setMnemonic('t');

action = new AbstractAction("Copy")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="";
textComponent.copy();
}
};

copyItem = popup.add(action);
copyItem.setMnemonic('c');
action = new AbstractAction("Paste")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="p";
savedstring=textComponent.getText();
System.out.println("in paste code savedstring is: "+savedstring);
textComponent.paste();
}
};

pasteItem = popup.add(action);
pasteItem.setMnemonic('p');

action = new AbstractAction("Delete")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="d";
savedstring=textComponent.getText();
textComponent.replaceSelection("");
}
};

deleteItem = popup.add(action);
deleteItem.setMnemonic('d');
popup.addSeparator();

action = new AbstractAction("Select All")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="s";
savedstring=textComponent.getText();
textComponent.selectAll();
}
};

selectAllItem = popup.add(action);
selectAllItem.setMnemonic('a');
}

public void mouseClicked(MouseEvent e)
{
//if (e.getModifiers()==InputEvent.BUTTON3_MASK)
if(SwingUtilities.isRightMouseButton(e))
{
if (!(e.getSource() instanceof JTextComponent))
{
return;
}

textComponent = (JTextComponent)e.getSource();
// 1.3 version
//textComponent.requestFocus();
// 1.4 preferred method
textComponent.requestFocus();
//textComponent.requestDefaultFocus();
//textComponent.requestFocusInWindow();


boolean enabled = textComponent.isEnabled();
boolean editable = textComponent.isEditable();
boolean nonempty = !(textComponent.getText()==null ||
textComponent.getText().equals(""));

boolean marked = textComponent.getSelectedText()!=null;
boolean pasteAvailable =
Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor);
undoItem.setEnabled(enabled && editable);
cutItem.setEnabled(enabled && editable && marked);
copyItem.setEnabled(enabled && marked);
pasteItem.setEnabled(enabled && editable && pasteAvailable);
deleteItem.setEnabled(enabled && editable && marked);
selectAllItem.setEnabled(enabled && nonempty);
popup.show(e.getComponent(),e.getX(), e.getY());
}
}

} // end PopupMenuMouseListener


*** END POPUP CODE *****

Adam

unread,
Feb 12, 2004, 8:46:06 AM2/12/04
to

"Al Murphy" <alm...@altavista.com> wrote in message
news:a23daf3f.0402...@posting.google.com...

> Folks,
>
> Interesting one here. I've implemented a right mouse click popup
> menu thingy that I found somewhere (code included below).
> It works perfectly using the appletviewer but when I view it in
> IE6.0 & NN7.1 I get the following error message
> "java.security.AccessControlException: access denied
> (java.awt.AWTPermission accessClipboard)":
> Would appreciate you comments...

I haven't looked at the rest of your message,
but it seems obvious that your applet
has no access to system clipboard.
Didn't you know that the applets have restricted permissions?


Adam


Thomas Weidenfeller

unread,
Feb 12, 2004, 8:42:11 AM2/12/04
to
Al Murphy wrote:
> Interesting one here. I've implemented a right mouse click popup
> menu thingy that I found somewhere (code included below).
> It works perfectly using the appletviewer but when I view it in
> IE6.0 & NN7.1 I get the following error message
> "java.security.AccessControlException: access denied
> (java.awt.AWTPermission accessClipboard)":
> Would appreciate you comments...

Works as designed. Accessing the system clipboard from an applet is
considered a security problem. Sign the applet, or don't do it :-)

/Thomas

Andrew Thompson

unread,
Feb 12, 2004, 8:50:55 AM2/12/04
to
Al Murphy wrote:
> Folks,
>
> Interesting one here. I've implemented a right mouse click popup
> menu thingy that I found somewhere (code included below).
> It works perfectly using the appletviewer but when I view it in
> IE6.0 & NN7.1 I get the following error message
> "java.security.AccessControlException: access denied
> (java.awt.AWTPermission accessClipboard)":

The applet would need to be _signed_
to access the clipboard.
http://java.sun.com/developer/Books/javaprogramming/JAR/sign/intro.html
http://java.sun.com/developer/Books/javaprogramming/JAR/sign/

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology


Al Murphy

unread,
Feb 13, 2004, 5:24:22 AM2/13/04
to
Folks,

Thanks for all your help. I'll look into signing this applet (can u
recommend any good tutorial sites).
In the mean time - I found a simple workaround. I commented out the
line:
Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor);

The applet now works fine apart from a *minor* visual bug. That is -
if the popup falls outside the boundary of the applet the botttom of
it picks up the term "Jaava applet" at the bottom and will not go
away. Compile it and you will see. It's not too annoying - the broad
mechanism is working.

Once again thanks for all your helps.

Cheers,
Al.

Andrew Thompson

unread,
Feb 13, 2004, 7:08:01 AM2/13/04
to
Al Murphy wrote:
> Folks,
>
> Thanks for all your help. I'll look into signing this applet (can u
> recommend any good tutorial sites).

See the links you trimmed..
search google, and, for the moment, stick to..
http://groups.google.com.au/groups?group=comp.lang.java.help

> In the mean time - I found a simple workaround. I commented out the
> line:
>
Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).isDataFla
vorSupported(DataFlavor.stringFlavor);

Glad you decided you did not need the
clipboard in an applet for the moment,
try things like that in a frame first.

The message that 'sticks on screen'
is probably more due to your HTML.

URL?

0 new messages