Image on System Clipboard

I am trying to put image on the SystemClipboard and paste it to another application (e.g. MSWord).

Transferable object ( the object that contains Image) is

set on the Clipboard all right.

(I am using Clipboard

clip=Toolkit.getDefaultToolkit).getSystemClipboard();)

However,actual System Clipboard is empty.

I am using jdk 1.3 on WindowsNT.

My question, is it supported functionality on jdk1.3 and I am doing something wrong or it is a known problem.

Thank you.

Leo

[544 byte] By [leoasin] at [2007-9-26 2:49:51]
# 1
Did anybody on this forum copied Images to system cllipboard with jdk 1.3?Let me know.Thank you.Leo
leoasin at 2007-6-29 10:36:03 > top of Java-index,Archived Forums,Swing...
# 2

hi,

here is the code sample, that works fine.

******************************************

From.java

******************************************

import java.awt.*;

import java.awt.event.*;

import java.awt.datatransfer.*;

public class From extends Frame implements ClipboardOwner, ActionListener {

Clipboard sysboard = getToolkit().getSystemClipboard();

TextArea txt;

Button copy;

String dataToCopy;

public static void main(String args[]){

From myFrame=new From();

myFrame.setSize(300,280);

myFrame.setTitle("From");

myFrame.show();

}

public From() {

GridBagLayout g=new GridBagLayout();

GridBagConstraints c=new GridBagConstraints();

setLayout(g);

txt=new TextArea(10,25);

copy=new Button("Copy");

c.gridx=0;

c.gridy=0;

c.gridwidth=3;

g.setConstraints(txt,c);

add(txt);

c.gridx=2;

c.gridy=1;

c.gridwidth=1;

g.setConstraints(copy,c);

add(copy);

copy.addActionListener(this);

validate();

}

public void actionPerformed(ActionEvent e){

Object source=e.getSource();

if(source instanceof Button){

StringSelection transferData;

dataToCopy=txt.getText();

if(dataToCopy!=null) {

transferData=new StringSelection(dataToCopy);

sysboard.setContents(transferData,this);

}

}

}

public void lostOwnership(Clipboard clipboard,Transferable contents) {

}

}

*****************************************

*****************************************

To.java

******************************************

import java.awt.*;

import java.awt.event.*;

import java.awt.datatransfer.*;

public class To extends Frame implements ActionListener {

Clipboard sysboard=getToolkit().getSystemClipboard();

TextArea txt;

Button paste;

public static void main(String args[]){

To myFrame=new To();

myFrame.setSize(300,280);

myFrame.setTitle("To");

myFrame.show();

}

public To() {

GridBagLayout g=new GridBagLayout();

GridBagConstraints c=new GridBagConstraints();

setLayout(g);

txt=new TextArea(10,25);

paste=new Button("Paste");

c.gridx=0;

c.gridy=0;

c.gridwidth=3;

g.setConstraints(txt,c);

add(txt);

c.gridx=2;

c.gridy=1;

c.gridwidth=1;

g.setConstraints(paste,c);

add(paste);

paste.addActionListener(this);

validate();

}

public void actionPerformed(ActionEvent e) {

String textCopied;

Transferable transferData;

Object source=e.getSource();

if(source instanceof Button) {

transferData=sysboard.getContents(this);

if(transferData!=null) {

try {

textCopied=(String)transferData.getTransferData(DataFlavor.stringFlavor);

txt.append(textCopied);

} catch(Exception ex) {

System.out.println("Error in getting contents from ClipBoard");

}

}

}

}

}

******************************************

Run both and try them out.

megamatrix at 2007-6-29 10:36:03 > top of Java-index,Archived Forums,Swing...
# 3

As far as I can understand this code MEGAMATRIX has posted is for copying Strings?!

I don't have any problems or doubts that String copying is working fine.

My problem is to copy IMAGE. I seems to be doing all the right things but there is nothing copied to Clipboard.

My question is: "If somebody was able to copy Image to the System clipboard using jdk1.3".

It look like in jdk1.4 it is supported better but I am interested in the moment in jdk 1.3

Thank you for your help.

Leo

leoasin at 2007-6-29 10:36:03 > top of Java-index,Archived Forums,Swing...
# 4
This problem is documented in the bug database with a solution it may be useful if your interested look for Bug ID 4498371 in the bug database and good luck.
middsco at 2007-6-29 10:36:03 > top of Java-index,Archived Forums,Swing...
# 5
The flavormap has been modified in JDK 1.4 so images to/from the clipboard now works. All you need to do now is to create a Transferable that uses an Image object.1000 times easier than pre JDK 1.4.
rockhopper at 2007-6-29 10:36:03 > top of Java-index,Archived Forums,Swing...
# 6
Realy? I have been trying for 2 weeks to create an applet that copies images from the system clipboard and have no luck. If somebody could send me working source code for that, I would be extremely gratefullmirthrandir63
mirthrandir63 at 2007-6-29 10:36:03 > top of Java-index,Archived Forums,Swing...
# 7
The reason I ask for source code is because most people seem to agree that it is possible to copy images, but none have been able to provide working source code for their idea.
mirthrandir63 at 2007-6-29 10:36:03 > top of Java-index,Archived Forums,Swing...