Clipboard in Java 1.1

I try to use clipboard in Java 1.1. version.
When data of clipboard is in String type it's ok,
but when data is Image, there is NullPointerException.
Transferable transferable = clipboard.getContents ( this );
variable transferable in this lines equlals null..
Help me someone please.

Use jdk 1.4 as that is the first version that supports transfering images to/from the clipboard.

Similar Messages

  • Pasting Image  from Mac clipboard to Java Based Application.

    Hi,
    I am working on "iMac 10.2.7". I need to paste an image from other
    application using "Java version 1.4.1". I am trying to retrieve the image
    from the system clipboard after it is copied from some other application. I
    am pasting the code which illustrates my requirement. It works fine on
    windows. But does not work on Mac.
    On Mac it does not cross the supported data flavor check
    (clipData.isDataFlavorSupported(DataFlavor.imageFlavor) where clipData is
    the Transferable object). It seems Mac has some InputStream instead of Image
    in the clipboard when some image is copied. I tried to read that InputStream
    using ImageIO.read(java.io.InputStream). But that is also returning null.
    Thanks
    Santanu
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.awt.datatransfer.*;
    import javax.swing.*;
    public class ClipboardTest extends JFrame implements KeyListener{
         JLabel label;
         static Toolkit kit = null;
         static Clipboard clipboard = null;
         public static void main (String arg[]) {
              kit = Toolkit.getDefaultToolkit();
              clipboard = kit.getSystemClipboard();
              JLabel l = new JLabel();
              JButton button = new JButton("Paste from clipboard");
              final ClipboardTest ct = new ClipboardTest(l);
              ct.getContentPane().add(l,BorderLayout.CENTER);
              ct.getContentPane().add(button,BorderLayout.SOUTH);
              ct.setVisible(true);
         button.addActionListener(
              new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        pasteImage(ct.label);
         button.addKeyListener(ct);
         public ClipboardTest (JLabel l) {
              label = l;
         public static void pasteImage(JComponent jComp) {
                   jComp.setTransferHandler(new ImageSelection());
                   TransferHandler handler = jComp.getTransferHandler();
                   Transferable clipData = clipboard.getContents(null);
              if (clipData != null) {
              if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                   handler.importData(jComp, clipData);
         //Key listener methods
         public void keyPressed(KeyEvent e) {
         int c = e.getKeyCode();
         if (c == 86) {
              if (e.isControlDown()) {
                   pasteImage(label);
         public void keyReleased(KeyEvent e) {}
         public void keyTyped(KeyEvent e) {}
    class ImageSelection extends TransferHandler implements Transferable {
         /* DataFlavor instance that holds imageflavor value*/
         private static final DataFlavor flavors[] = {DataFlavor.imageFlavor};
         private Image image;
         public boolean importData(JComponent comp, Transferable transferable) {
         try {
         if (transferable.isDataFlavorSupported(flavors[0])) {
         image = (Image)transferable.getTransferData(flavors[0]);
                   if (comp instanceof JLabel) {
                   ((JLabel)comp).setIcon(new ImageIcon(image));
                   comp.repaint();
                   return true;
         } catch (Exception ignored) {
              ignored.printStackTrace();
         return false;
         // Transferable Interface methods
         public Object getTransferData(DataFlavor flavor) {
         if (isDataFlavorSupported(flavor)) {
         return image;
         return null;
         public DataFlavor[] getTransferDataFlavors() {
         return flavors;
         public boolean isDataFlavorSupported(DataFlavor flavor) {
         return flavor.equals(flavors[0]);

    Here are two commercial options:
    JTwain + JSane
    http://asprise.com/product/jtwain/index.php
    Morena
    http://www.gnome.sk/Twain/jtp.html
    Haven't tested them, so don't no how good they are, nor how easy they are to use on multiple platforms.

  • Using system clipboard w/ java

    Does anyone know how java can input a string into the system clipboard that can be accessed later?

    public void Copyit() {
          try{
          getit = area.getSelectedText();
          c = Toolkit.getDefaultToolkit().getSystemClipboard();
           Transferable contents = clipboard.getContents( im );
               c.setContents( contents, null );
              if(getit.equalsIgnoreCase("null")){ throw null; }
           }catch(NullPointerException nul){ System.out.print("Clipboard is emty");} 
      public void Pasteit() {
              c = Toolkit.getDefaultToolkit().getSystemClipboard();
              Transferable contents = c.getContents(this);
              String getit1 = "";
              try {
                getit1 = ( String ) contents.getTransferData( DataFlavor.stringFlavor );
            if(getit.equalsIgnoreCase("null")) { getit = null;
               throw null; }
               else
                field.setText(getit1);
             }catch(NullPointerException e ) {
               System.out.println( "Unable to read system clipboard" ); }    catch(Exception ee ) {
               System.out.println( "Unable to read system clipboard" ); }
    }here is two function that will work on a textfild/textarea you just have to piece the rest together which is not much or hard

  • Using clipboard with java

    Is there a way to take a string and input in into a field on a seperate program? (Such as input a string into an open file box in notepad. Notepad is already open and the open window is already open.)

    Sending key presses is pretty simple, i was wondering if there was a way to use the system clipboard, then just use the ctrl+V keypress, rather than converting the entire string to keypresses, cause that takes more processing time as far as i can tell

  • Need to save the image saved in the System Clipboard in using JDK 1.3.1

    Does anyone know how to use JDK 1.3.1 to take an image saved in the System clipboard and save it to a file using the JPG format?
    I know how it is done in JDK 1.4 using the following code. Unfortunately, the same code does not recognize the image in the clipboard in JDK 1.3.1
    I am using jai-1_1_2_01.
    package clipboard;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.image.RenderedImage;
    import java.awt.Toolkit;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.io.IOException;
    import java.io.FileOutputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import javax.media.jai.JAI;
    import javax.media.jai.RenderedOp;
    public class clipboard
    {  private File tempFile = null;
    * @param args
    static int BUFFER_SIZE = 65536;
    public static void main(String[] args)
    {  clipboard clip = new clipboard();
    clip.writeImageFromClipboard();
    public void writeImageFromClipboard()
    {  Clipboard            clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable transferable = clip.getContents(null);
    RenderedImage img = null;
    FileOutputStream fileOutStr = null;
    BufferedOutputStream bufOutStr = null;
    DataFlavor [] dataFlavors;
    File tempFile;
    int
    byteCount;
    String [] strArr;
    dataFlavors = transferable.getTransferDataFlavors();
    System.out.println("clip=" + clip.getName());
    System.out.println("Transferable=" + transferable);
    for (int i = 0; i < dataFlavors.length; i++)
    {  System.out.println("dataFlavours[" + i + "]=" + dataFlavors.toString());
    if (transferable.isDataFlavorSupported(new DataFlavor("image/x-java-image; class=java.awt.Image", "Image")))
    { try
    { img = (RenderedImage) transferable.getTransferData(new DataFlavor("image/x-java-image; class=java.awt.Image", "Image"));
    if (this.tempFile == null)
    { this.tempFile = File.createTempFile("__TMP_IMG__", ".jpg");
    System.out.println(this.tempFile.getCanonicalPath());
    fileOutStr = new FileOutputStream(this.tempFile);
    bufOutStr = new BufferedOutputStream(fileOutStr);
    // Encode the file as a JPG image.
    JAI.create("encode", img, bufOutStr, "JPEG", null);
    catch (UnsupportedFlavorException e)
    { e.printStackTrace();
    catch (IOException e)
    { e.printStackTrace();
    finally
    { if (bufOutStr != null)
    { try
    { bufOutStr.flush();
    bufOutStr.close();
    catch (IOException e)
    if (fileOutStr != null)
    { try
    { fileOutStr.flush();
    fileOutStr.close();
    catch (IOException e)
    else
    { System.out.println("Not an image!");

    The login  you connected to the server  and run the above statement does not have permissions to operate  on this path "C:\Users\ISLLCdba\Desktop\MAA
    PROFILE PICTURES\"
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Writing Image in the clipboard to Oracle DB

    Hi,
    I want to write the image in the clipboard to the Blob am using JDeveloper. Can any1 help me please I am stuck on conversion and writing to Blob.
    Very Urgent Please!!!!!!!
    Comments: Applet is used to diplay an image present in the clipboard, convert this image into bytes write it to a blob and transfer the blob into Oracle DB
    package mypackage1;
    import java.applet.Applet;
    import javax.swing.JLabel;
    import oracle.jdeveloper.layout.XYLayout;
    import oracle.jdeveloper.layout.XYConstraints;
    import java.awt.datatransfer.*;
    import java.awt.image.*;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.event.*;
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import oracle.jdeveloper.layout.OverlayLayout2;
    import java.awt.Button;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.sql.Blob;
    import java.sql.Statement;
    import java.awt.Toolkit;
    import java.awt.event.*; //Clipboard
    import java.awt.datatransfer.*; //Clipboard
    import java.awt.Image;// .image.*; //Clipboard
    import java.sql.*;
    import java.sql.*;
    import java.net.*;
    import java.lang.*;
    import java.awt.TextField;
    import java.awt.Font;
    import oracle.sql.BLOB;
    public class ClipboardImage extends Applet
    Button displayButton = new Button();
    Button exitButton = new Button();
    JLabel photoLabel = new JLabel();
    Panel panel1 = new Panel();
    XYLayout xYLayout2 = new XYLayout();
    XYLayout xYLayout1 = new XYLayout();
    Button submitButton = new Button();
    Connection connection = null;
    static Image photo;
    public byte[] data;
    public Blob bl;
    TextField Message = new TextField();
    public ClipboardImage()
    public void init()
    try
    jbInit();
    catch(Exception e)
    e.printStackTrace();
    public static void main(String[] args)
    ClipboardImage applet = new ClipboardImage();
    Frame frame = new Frame();
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    frame.add(applet, BorderLayout.CENTER);
    frame.setTitle("Applet Frame");
    applet.init();
    applet.start();
    frame.setSize(300, 300);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation((d.width - frameSize.width) / 2, (d.height -
    frameSize.height) / 2);
    frame.setVisible(true);
    private void jbInit() throws Exception
    this.setLayout(xYLayout2);
    this.setBackground(new Color(136, 212, 122));
    displayButton.setLabel("Display");
    displayButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    scanButton_actionPerformed(e);
    exitButton.setLabel("Exit");
    exitButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    exitButton_actionPerformed(e);
    photoLabel.setText("Photo");
    panel1.setLayout(xYLayout1);
    panel1.setBackground(new Color(255, 249, 240));
    xYLayout2.setWidth(288);
    xYLayout2.setHeight(300);
    submitButton.setLabel("Submit");
    submitButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    submitButton_actionPerformed(e);
    Message.setFont(new Font("Abadi MT Condensed", 0, 9));
    panel1.add(photoLabel, new XYConstraints(0, 0, 115, 155));
    this.add(Message, new XYConstraints(20, 275, 250, 15));
    this.add(submitButton, new XYConstraints(105, 220, 80, 30));
    this.add(panel1, new XYConstraints(90, 25, 115, 155));
    this.add(exitButton, new XYConstraints(195, 220, 85, 30));
    this.add(displayButton, new XYConstraints(10, 220, 85, 30));
    void exitButton_actionPerformed(ActionEvent e)
    System.exit(0);
    If an image is on the system clipboard, this method returns it
    otherwise it returns null
    public static Image getClipboard()
    Transferable t =
    Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    try
    if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor))
    Image text = (Image)t.getTransferData(DataFlavor.imageFlavor);
    photo = text;
    return text;
    catch (UnsupportedFlavorException e)
    catch (IOException e)
    return null;
    Display an image in the system's clipboard
    void scanButton_actionPerformed(ActionEvent e)
    Image img = this.getClipboard();
    photo = img;
    photoLabel.setIcon(new ImageIcon(photo));
    // Gives out int array
    public int[] fetchPixels(Image image, int width, int height)
    int pixMap[] = new int[width*height];
    PixelGrabber pg = new PixelGrabber(image, 0,0,width,height, pixMap,
    0, width);
    try
    pg.grabPixels();
    catch (InterruptedException e)
    return null;
    if((pg.status() & ImageObserver.ABORT)!=0)
    return null;
    return pixMap;
    // Here int array given by Pixel Grabber function is converted into
    byte array
    public byte[] extractData(int[] pixmap, int numbands) {
    byte data[] = new byte[pixmap.length*numbands];
    for(int i=0;i<pixmap.length;i++){
    int pixel = pixmap;
    byte a = (byte)((pixel >> 24) & 0xff);
    byte r = (byte)((pixel >> 16) & 0xff);
    byte g = (byte)((pixel >> 8) & 0xff);
    byte b = (byte)((pixel ) & 0xff);
    if(numbands == 4){
    data[i*numbands+0] = r;
    data[i*numbands+1] = g;
    data[i*numbands+2]= b;
    data[i*numbands+3] = a;
    } else {
    data[i*numbands+0] = r;
    data[i*numbands+1] = g;
    data[i*numbands+2]= b;
    return data;
    public void processData() {
    Image awtImage = getClipboard();
    int imageWidth = awtImage.getWidth(this);
    int imageHeight = awtImage.getHeight(this);
    int[] pix = fetchPixels(awtImage, imageWidth, imageHeight);
    data = extractData(pix, 4);
    photo = awtImage;
    System.out.println(" Height = " + imageHeight + " Width = " +
    imageWidth + " Pixel = " + pix + " Byte = " + data);
    void submitButton_actionPerformed(ActionEvent e)
    processData();
    try {
    System.out.println("Executing code");
    // Load the JDBC driver
    String driverName = "oracle.jdbc.driver.OracleDriver";
    Class.forName(driverName);
    // Create a connection to the database
    String serverName = "10.20.90.101";
    String portNumber = "1521";
    String sid = "iasdb";
    String url = "jdbc:oracle:thin:@" + serverName + ":" +
    portNumber + ":" + sid;
    String username = "birmingham";
    String password = "in";
    connection = DriverManager.getConnection(url, username,
    password);
    PreparedStatement ast = connection.prepareStatement("INSERT
    INTO PASSPORT (PASSID, PHOTO) VALUES (1992, EMPTY_BLOB())");
    ast.executeUpdate();
    PreparedStatement pst = connection.prepareStatement("UPDATE
    PASSPORT SET PHOTO = ? WHERE PASSID = 1992");
    //pst.setObject(1, (Object)photo);
    //Writing bytes to blob bl
    bl.setBytes(0, data);
    //Setting the blob to transfer to the blob column in oracle
    db
    pst.setBlob(1, bl);
    pst.executeUpdate(); if(pst.EXECUTE_FAILED == 1)
    Message.setText("Sql failed!");
    }else{
    Message.setText("Sql success!");
    System.out.println ("Connected\n");
    } catch (ClassNotFoundException ea) {
    // Could not find the database driver
    } catch (SQLException ea) {
    System.out.println(ea.toString());

    Look at the ArrayListTransferHandler class in the following Drag List Demo example: http://www.java2s.com/Code/Java/Swing-JFC/DragListDemo.htm

  • Detect something just copied to the clipboard

    Hi everyone,
    I'm wondering if it is possible for a java program to detect something just got copied into the system's clipboard? I don't mind using JNI if that helps. I need to be notified after a user "right click and select copy" in any application. They can be copying something in microsoft word and i want to be notified in my java program when a copy-to-clipboard is just made. Is this even possible in Java? I searched the forumn and didn't see any topic on this. TIA

    Run this program, it is an example of monitoring the clipboard.
    import java.awt.*;
    import java.awt.datatransfer.*;
    class MyClipboardOwner implements ClipboardOwner {
        public void lostOwnership(Clipboard clipboard, Transferable contents) {
            System.out.println ("Someone copied something to the clipboard");
            DataFlavor[] df = contents.getTransferDataFlavors();
            for (int i = 0; i < df.length; ++i) {
                System.out.println (df);
    public class Test105 {
    public static void main(String[] args) throws Exception {
    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    cb.setContents(new StringSelection ("Put this in the clipboard"), new MyClipboardOwner());
    while (true) {
    try { Thread.sleep(100); } catch (InterruptedException ex) {}

  • How to a copy a tif image to system clipboard and paster in MS Word

    import java.awt.image.RenderedImage;
    import java.io.IOException;
    import javax.media.jai.RenderedImageAdapter;
    import util.TIFFFileHelper;
    public class ClipboardSupport implements ClipboardOwner{
         public ClipboardSupport() {
              super();
         public static void main(String[] args) throws IOException {
              ClipboardSupport co = new ClipboardSupport();
              RenderedImage img=co.getTestImage();
              co.copyToClipBoard(img);
         private RenderedImage getTestImage() throws IOException{
              TIFFFileHelper th = new TIFFFileHelper("C:/workspace/AV/src/images/onepageSample.tif");
              th.getPageCountParseFirstPage();
              RenderedImage img = th.getFirstPage();
              return img;
         public void copyToClipBoard(RenderedImage img2){
              Image img=this.getCovertedImage(img2);
              this.copyToClipBoard(img);
         public void copyToClipBoard(Image img){
              Toolkit tkt = Toolkit.getDefaultToolkit();
              Clipboard clipboard = tkt.getSystemClipboard();
              Transferable t = new ImageSelection(img);
              clipboard.setContents(t,this);
         public void lostOwnership(Clipboard clipboard, Transferable contents) {
              System.out.println("ClipboardSupport.lostOwnership() called");
         private Image getCovertedImage(RenderedImage img) {
              RenderedImageAdapter aid = new RenderedImageAdapter(img);
              Image im = aid.getAsBufferedImage();
              return im;
    package util.clipboard;
    import java.awt.Image;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.io.IOException;
    public class ImageSelection implements Transferable {
         private Image img=null;
         DataFlavor dataFlavor = DataFlavor.imageFlavor;
         public ImageSelection(Image img) {
              super();
              this.img=img;
         public DataFlavor[] getTransferDataFlavors() {          
              DataFlavor[] data = new DataFlavor[1];
              data[0]=dataFlavor;
              return data;
         public boolean isDataFlavorSupported(DataFlavor flavor) {          
              if(dataFlavor.equals(flavor)){
                   return true;
              }else{
                   return false;
         public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
              return img;
    }

    done.

  • Native -- DataFlavor clipboard problem

    I'm trying to access vim specific clipboard data (to get visual block info). This is on windows XP (unix is next) I've registered the formats with addFlavorForUnencodedNative, see java code below. But when I look at all the clipboard flavors, when clipboard contains vim stuff, no vim flavors show up, see output.
    Any ideas of what/where the problem might be?
    Thanks,
    -ernie
    In vim, from its os_win32.c, there is
        clip_star.format = RegisterClipboardFormat("VimClipboard2");
        clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");and when a vim copy to clipboard command is issued, in vim's os_mswin.c. Note that cbd->format is clip_start.format, returned from RegisterClipboardFormat above.
    SetClipboardData(cbd->format, hMemVim);
    SetClipboardData(CF_UNICODETEXT, hMemW) != NULL)
    SetClipboardData(CF_TEXT, hMem);When I run the java program I get the following output. First are the mimetype of the 3 native flavors I added; in cb.getAvailableDataFlavors() none of them appear in the 27 flavors available.
    VimClipboard application/vimclipboard; class=java.nio.ByteBuffer
    VimClipboard2 application/vimclipboard2; class=java.nio.ByteBuffer
    VimRawBytes application/vimrawbytes; class=java.nio.ByteBuffer
    27 flavors
    application/x-java-text-encoding; class="[B"
    application/x-java-serialized-object; class=java.lang.String
    ...Here's the java code that is not finding the vim clipboard native data
    /* Main.java; access vim's clipboard */
    package vimclipapp;
    import java.awt.Toolkit;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.FlavorMap;
    import java.awt.datatransfer.SystemFlavorMap;
    public class Main {
        static DataFlavor VimClipboard = addFlavor("VimClipboard");
        static DataFlavor VimClipboard2 = addFlavor("VimClipboard2");
        static DataFlavor VimRawBytes = addFlavor("VimRawBytes");
        static DataFlavor addFlavor(String cbName) {
            DataFlavor df = null;
            FlavorMap fm = SystemFlavorMap.getDefaultFlavorMap();
            SystemFlavorMap sfm = (SystemFlavorMap) fm;
            try {
                df = new DataFlavor(  "application/"
                                    + cbName
                                    + "; class=java.nio.ByteBuffer");
            } catch (ClassNotFoundException ex) { ex.printStackTrace(); }
            System.err.println(cbName + " " + df.getMimeType());
            sfm.addFlavorForUnencodedNative(cbName, df);
            sfm.addUnencodedNativeForFlavor(df, cbName);
            return df;
        public static void main(String[] args) {
            Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
            if(cb.isDataFlavorAvailable(VimClipboard2))
                System.err.println("VimClipboard available");
            DataFlavor dfa[] = cb.getAvailableDataFlavors();
            System.err.println("\n" + dfa.length + " flavors\n");
            for (DataFlavor df : dfa) {
                System.err.println(df.getMimeType());
    }

    Are you using Gmail?
    Try deleting the email profile, tap battery, tap restart, go into email and reinstall the profile.

  • Writing on system clipboard from an applet.

    Is it possible?
    I have tried to write on it but an exception is occoured:
    java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)
    The code that I have used is:
    import java.security.*;
    import java.awt.*;
    import java.awt.datatransfer.*;
    import javax.swing.*;
    public class Blah extends JApplet {
    public void init() {
    String exampleStr = "Hi!";
    Clipboard clipboard;
    Transferable trans;
    StringSelection strSelect;
    try {
    SecurityManager security = System.getSecurityManager();
    if (security != null)
    security.checkSystemClipboardAccess();
    clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
    strSelect = new StringSelection(exampleStr);
    trans = (Transferable)strSelect;
    clipboard.setContents(trans, strSelect);
    System.out.println("Clipboard copy successful");
    catch (Exception e) {
    System.err.println("Clipboard copy failed");
    System.err.println(e);
    Thanks

    First, your applet must be signed to access the system clipboard. And on Netscape 4.7.x, you need to enable the privilege from within the same method where you get the system clipboard. On IE 5.5/6.0, signing the applet is all that is necessary.
    Here's what I do on Netscape:
    Make sure when you call "PrivilegeManager.enablePrivilege("UniversalSystemClipboardAccess");", that you get the system clipboard within the same method. Failure to do this will cause a ForbiddenTargetException.
    My code looks like:
    public java.awt.datatransfer.Clipboard getSystemClipboard()
    java.awt.datatransfer.Clipboard clipboard = null;
    try
    PrivilegeManager.enablePrivilege("UniversalSystemClipboardAccess");
    clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    PrivilegeManager.revertPrivilege("UniversalSystemClipboardAccess");
    catch (netscape.security.ForbiddenTargetException se)
    se.printStackTrace();
    catch(Exception e)
    e.printStackTrace();
    return clipboard;
    This works successfully on Netscape 4.7.8. On IE 5.5/6.0, I didn't have to do anything other than having a signed applet to get the system clipboard. With the code above, I also am using a signed applet.
    Hope this helps anyone else trying to make this work.
    -Dave.

  • JTextPane and Clipboard

    Hi!
    I am using JDK 1.3 and JDK 1.4 and I've got the following question:
    If I use the javax.swing.JTextPane object, I can define a javax.swing.text.DefaultEditorKit and other actions in order to implement copy/paste functionality. My question is: Which clipboard is used here? The java api documentation of javax.swing.text.DefaultEditorKit.PasteAction states that the system clipboard is used.
    But this particular applet I am using is not permitted to use the system clipboard, I cannot get the system clipboard from java.awt.Toolkit, it throws an exception.
    The reason for me writing the question into that forum is that I want to manually access the clipboard that is used by my JTextPane object.
    Ciao
    Tobi

    Read the discussions at the link shown below especially my reply #11:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=355974
    ;o)
    V.V.

  • Copying drawing objects from MS word to clipboard

    Hi all,
    Is there any way to copy anything from ms-word and store it in the file and retreive that back from file and paste it back to ms-word ?
    I have a applet that is able to copy string and image data independently from clipboard to java and vise versa. I am not able to do the same with organization chart or any mixture of string and image data. I am not even sure about the DataFlavor to use. Can some one please suggest any possible solution ?
    I tried with "image/x-java-image;class=java.awt.Image" and
    "text/rtf; class=java.io.InputStream". but unable to get any result from clipboard.
    My requirement is to store some charts from ms-word to java and later on retrieve them back to java into ms-word and make modification in the chart.
    Thanks in advance,
    Sid

    Any idea on this .................... Pleeeeease :-(

  • Unable to copy text values in CLipboard in Ubuntu 8.1

    Hi all ,
    Im using the following code to copy the text:
    import java.awt.Toolkit;
    import java.awt.datatransfer.Clipboard;
    import java
         .awt
         .datatransfer
         .StringSelection;
    import java
         .awt
         .datatransfer
         .Transferable;
    public class TextWriter {
         public static void writeToClipboard(String writeMe) {
              // get the system clipboard
              Clipboard systemClipboard =
                   Toolkit
                        .getDefaultToolkit()
                        .getSystemClipboard();
              // set the textual content on the clipboard to our
              // transferable object
              // we use the
              Transferable transferableText =
                   new StringSelection(writeMe);
              systemClipboard.setContents(
                   transferableText,
                   null);
         public static void main(String[] args) {
              System.out.println(
                   "Writing text to the system clipboard.");
              String writeMe =
                   "I'd like to be put on the clipboard";
              writeToClipboard(writeMe);
    }After running the application when I try to paste it in GEDIT , it is not pasting .
    Also in menubar the PASTE is also not getting enable.
    Can anybody tell how to copy text .
    OS used Ubuntu 8.1 and java version 1.6 update 10
    Thanks and regards
    Anshuman Srivastava

    Copy cannot be disabled to my knowledge. Did you try quitting Safari and resetting your iPad? To quit an app double click the Home button to reveal the row of recently used apps. Flick up on the page preview and it will fly away and disappear. That quits the app. Then Press and hold both the Home button and the Sleep/Wake button continuously until the Apple logo appears. Then release the button and let the device restart. You will not lose data doing this. It's like a computer reboot.

  • Copy paste from windows clipboard to JTextField

    I am making a swing application with a lot of components in it. There are a lot of JtextFields in the application. when i do Ctrl+C from a JTextField and do a Ctrl V in a different JTextField of the same application the text gets copied to the second JTextField. But when i copy something from windows and try to paste it in JTextField it does'nt work. Please guide me. Some other component is eating up the Ctrl C/Ctrl V event or what?
    I tried adding keystroke's to the InputMap of the JTextField but it still does'nt work.
    Kindly guide me. Thanks in advance
    Excerpts from the code:
    JTextField text1 = new JTextField();
    KeyStroke copykeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK);
    KeyStroke pastekeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK);
    text1.getInputMap().put(copykeystroke, "copy-to-clipboard");
    text1.getInputMap().put(pastekeystroke, "paste-from-clipboard");

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class CutCopyPaste {
      public static void main(String[] args) {
        Action cut = new TextAction("cut") {
          public void actionPerformed(ActionEvent e) {
            getFocusedComponent().cut();
        Action copy = new TextAction("copy") {
          public void actionPerformed(ActionEvent e) {
            getFocusedComponent().copy();
        Action paste = new TextAction("paste") {
          public void actionPerformed(ActionEvent e) {
            getFocusedComponent().paste();
        JMenu menu = new JMenu("edit");
        menu.add(cut);
        menu.add(copy);
        menu.add(paste);
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(menu);
        JTextField textField = new JTextField(15);
        JPanel northPanel = new JPanel();
        northPanel.add(textField);
        JTextArea textArea = new JTextArea(5,25);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setMargin(new Insets(5,10,5,10));
        JPanel panel = new JPanel();
        panel.add(new JScrollPane(textArea));
        JFrame f = new JFrame("Cut Copy Paste");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setJMenuBar(menuBar);
        f.getContentPane().add(northPanel, "North");
        f.getContentPane().add(panel);
        f.setSize(400,180);
        f.setLocation(400,300);
        f.setVisible(true);
    }

  • Copy a Dicom Image to Clipboard

    hello,
    Iam trying to copy a DICOM image to clipboard using java swing.
    But at the time of copy it shows the following Exception.
    com.sun.medialib.codec.png.PNGException:
    codecLib: image palette error. [PLTE]
    at com.sun.medialib.codec.png.Encoder.setPalette(Encoder.java:187)
    at com.sun.media.imageioimpl.plugins.png.CLibPNGMetadata.writeMetadata(CLibPNGMetadata.java:2616)
    at com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriter.write(CLibPNGImageWriter.java:198)
    Iam using the code part to copy the image is:------
    public void setClipboard() {
    m_bufImage = m_origImage = m_currBean.getImage();
    if (m_bufImage != null) {
    ImageSelection imgSel = new ImageSelection(m_bufImage);
    try{
    Clipboard clipboard = Toolkit.getDefaultToolkit ().getSystemClipboard();
    clipboard.setContents(imgSel,null);
    }catch(Exception e){
    e.printStackTrace();
    If anybody is familier with this error please send me a solution to solve this problem.
    thanks in advance
    suryasri

    Hi,
    try to read this SUN article.
    http://developer.java.sun.com/developer/technicalArticles/releases/data/
    Hope this help you.
    Bye
    Ste

Maybe you are looking for

  • Can i transfer my passport to g drive?

    I transferred photos from my old imac to my passport, now i got a new imac and i wanna load the pictures up from my passport, but i bought a bigger g drive to store them, can i go from my passport to g drive or do i have to go via my imac..    i have

  • WHY DOES IT ACT LIKE I AM OPENING ITUNES UP FOR THE FIRST TIME

    WHY DOES IT ACT LIKE I AM OPENING ITUNES UP FOR THE FIRST TIME

  • Output from dbms_output.put_line splits and move to next line

    Hi All, I am printing out a list using dbms_output.put_line its like One or more of following Required Parameters are missing: 1. Primary Field 2. Structure Field 3. Structure Table 4. List File Name 5. Query Directory 6. Query String but I don't kno

  • Flex Data Service : deployment and reusage

    I am currently trying out different deployment methods to deploy the flex.war on JBoss. So far the WAR-file itself and any other EAR/WAR that contains the contents of flex.war run properly. However as far as I understood this file is merely a templat

  • Turn off in-chat sounds

    Ever since updating to the newest version of desktop skype, I get a sound notifications whenever im actively using the skype window. More specifically whenever someone sends an IM, its pings. Making group chats aggrivating to participate in. I have s