Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6607163

Linux: Cannot copy image from Java to OpenOffice

XMLWordPrintable

    • b25
    • x86
    • linux, linux_2.6
    • Not verified

        FULL PRODUCT VERSION :
        java version "1.6.0_02"
        Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
        Java HotSpot(TM) Server VM (build 1.6.0_02-b05, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux thinkpad-x60 2.6.20-16-generic #2 SMP Fri Aug 31 00:55:27 UTC 2007 i686 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        Copy an image to the clipboard (using DataFlavor.imageFlavor). Paste the image into a Java application that takes images from the clipboard. It works fine. Paste into OpenOffice or the Gimp. Nothing is pasted.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the program below. Then try to paste into OpenOffice.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        An image of a red square should be pasted into OpenOffice.
        ACTUAL -
        Nothing is pasted.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.*;
        import java.awt.datatransfer.*;
        import java.awt.image.*;
        import javax.swing.*;

        /**
         * This program demonstrates the transfer of images between a Java application and the system
         * clipboard.
         * @version 1.22 2007-08-16
         * @author Cay Horstmann
         */
        public class ImageTransferTest2
        {
           public static void main(String[] args)
           {
              EventQueue.invokeLater(new Runnable()
                 {
                    public void run()
                    {
                       JFrame frame = new JFrame();
                       frame.setSize(100, 100);
                       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                       frame.setVisible(true);
                       BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
                       Graphics g = image.getGraphics();
                       g.setColor(Color.RED);
                       g.fillRect(25, 25, 50, 50);
                       Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                       ImageSelection selection = new ImageSelection(image);
                       clipboard.setContents(selection, null);
                    }
                 });
           }
        }

        class ImageSelection implements Transferable
        {
           /**
            * Constructs the selection.
            * @param image an image
            */
           public ImageSelection(Image image)
           {
              theImage = image;
           }

           public DataFlavor[] getTransferDataFlavors()
           {
              return new DataFlavor[] { DataFlavor.imageFlavor };
           }

           public boolean isDataFlavorSupported(DataFlavor flavor)
           {
              return flavor.equals(DataFlavor.imageFlavor);
           }

           public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
           {
              if (flavor.equals(DataFlavor.imageFlavor))
              {
                 return theImage;
              }
              else
              {
                 throw new UnsupportedFlavorException(flavor);
              }
           }

           private Image theImage;
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Run Windows.

              son Oleg Sukhodolsky (Inactive)
              igor Igor Nekrestyanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: