File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Accesing system clipboard in Applet    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Applets
Bookmark "Accesing system clipboard in Applet    " Watch "Accesing system clipboard in Applet    " New topic

Accesing system clipboard in Applet

Rajiv Karambalkar

Joined: Dec 06, 2006
Posts: 2
have designed a applet where i have created my own buttons . cut, copy and paste. and have used javax.swing.text.DefaultEditorKit
DefaultEditorKit.cutAction,DefaultEditorKit.copyActionDefaultEditorKit.pasteAction action classes to access system's clipboard.

For the first time when it loads at the client side(in Browser) , applet is not able to access the system clipboard, but when i start that same applet after closing it , it can able to
access the system's clipboard. I mean , for first time, i can not paste data from external application like notepad, but for next time onwards, i can paste the data copied from Notepad.

Can anybody help me out to find , why its not happening for the first time.
Rajiv Karambalkar

Joined: Dec 06, 2006
Posts: 2
I have written following code.
package com.applet;
import java.applet.Applet;
import java.util.Hashtable;
import javax.swing.Action;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.text.DefaultEditorKit;

public class ClipBoard extends Applet {
JTextField textField = null;
Action actions[] = null;
JButton cutButton = null;
JButton copyButton = null;
JButton pasteButton = null;

public void init() {
textField = new JTextField(20);
actions = textField.getActions();
Action cutAction = findAction(actions, DefaultEditorKit.cutAction);
Action copyAction = findAction(actions, DefaultEditorKit.copyAction);
Action pasteAction = findAction(actions, DefaultEditorKit.pasteAction);

cutButton = new JButton(cutAction);

copyButton = new JButton(copyAction);

pasteButton = new JButton(pasteAction);

public static Action findAction(Action actions[], String key) {
Hashtable<Object, Action> commands = new Hashtable<Object, Action>();
for (int i = 0; i < actions.length; i++) {
Action action = actions[i];
commands.put(action.getValue(Action.NAME), action);
return commands.get(key);
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<APPLET CODE="com.applet.ClipBoard.class" WIDTH=460 HEIGHT=160></APPLET>
I agree. Here's the link:
subject: Accesing system clipboard in Applet