Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accesing system clipboard in Applet  RSS feed

Rajiv Karambalkar
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!