Copying image to jpanel

when i copy an image to jpanel using jlabel i.e
jlabel lab = new jlabel(new Iconimage("xyz.jpg"));
i cannot listen to any keys being pressed on the label when i want to copy the image onto a clip board( cntrl C). Is there any method of listening to keys being pressed on jlabel or a method to display the image on jpanel which listens to keys.

can give code to draw image on Panel.
icon = new ImageIcon("backUp.gif");
JPanel panel = new JPanel()
     protected void paintComponent(Graphics g)
          g.drawImage(icon.getImage(), 0, 0, null);
          super.paintComponent(g);
panel.setOpaque( false );

Similar Messages

  • Adding Image to JPanel?

    Hi all,
    I am new to Swing..
    How to add the "Image" to JPanel.
    if anyone knows please help me..
    Thanks

    Here's a long reply involving several classes, some obtained directly from Sun for reuse. These allow you to fill an image in a panel as the background to your frame. You can add components on top of this background image. If this isn't what you wanted, excuse my misunderstanding:
    First, you need a panel for your frame:
    <code>
    public class FramePanel extends JPanel
    * Initialized by the (first call to the) constructor. This
    * Fill is used to paint the entire panel.
    private static TiledFill tiledFill = null;
    /*Constructors */
    public FramePanel()
    super();
    setOpaque(true);
    * Create a TiledFill object to draw the
    * background from preferences properties file
    public void getBackgroundImage()
    setForeground(Color.BLACK);
    setBackground(Color.WHITE);
    if (tiledFill == null)
    try
    FileImageInputStream file = new FileImageInputStream(*your image's file location*);
    BufferedImage image = ImageIO.read(file);
    ImageFill fill = new ImageFill(image);
    tiledFill = new TiledFill(fill, image.getWidth(), image.getHeight());
    catch (IOException e)
    e.printStackTrace();
    JOptionPane pane = new JOptionPane("Could not retrieve image in FramePanel");
    pane.setVisible(true);
    * Paint the area within <code>g.getClipBounds()</code>
    * making sure that the new tiles are aligned with a tileWidth
    * by tileHeight grid whose origin is at 0,0.
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    getBackgroundImage();
    /* To ensure that the tiles we paint are aligned with
    * a tileWidth X tileHeight grid whose origin is 0,0 we
    * enlarge the clipBounds rectangle so that its origin
    * is aligned with the origin of a tile and its size
    * is a multiple of the tile size.
    Rectangle clip = g.getClipBounds();
    int tw = tiledFill.getTileWidth();
    int th = tiledFill.getTileHeight();
    int x = (clip.x / tw) * tw;
    int y = (clip.y / th) * th;
    int w = (((clip.x + clip.width + tw - 1) / tw) * tw) - x;
    int h = (((clip.y + clip.height + th - 1) / th) * th) - y;
    Graphics gFill = g.create();
    tiledFill.paintFill(this, gFill, new Rectangle(x, y, w, h));
    gFill.dispose();
    </code>
    Now you need the fill and tiled fill classes size the image.
    <code>
    import java.awt.*;
    public class Fill
    public void paintFill(Component c, Graphics g, Rectangle r)
    g.setColor(c.getBackground());
    g.fillRect(r.x, r.y, r.width, r.height);
    public void paintFill(Container c, Graphics g)
    Insets insets = c.getInsets();
    int x = insets.left;
    int y = insets.top;
    int w = c.getWidth() - (insets.left + insets.right);
    int h = c.getHeight() - (insets.top + insets.bottom);
    paintFill(c, g, new Rectangle(x, y, w, h));
    public void paintFill(Component c, Graphics g, int x, int y, int w, int h)
    paintFill(c, g, new Rectangle(x, y, w, h));
    </code>
    <code>
    import java.awt.*;
    import java.awt.image.*;
    * Displays a single <code>BufferedImage</code>, scaled to fit the
    * <code>paintFill</code> rectangle.
    * <pre>
    * BufferedImage image = ImageIO.read(new File("background.jpg"));
    * final ImageFill imageFill = new ImageFill(image);
    * JPanel p = new JPanel() {
    * public c void paintComponent(Graphics g) {
    *     imageFill.paintFill(this, g);
    * </pre>
    * Note that animated gifs aren't supported as there's no image observer.
    public class ImageFill extends Fill
    private final static int IMAGE_CACHE_SIZE = 8;
    private BufferedImage image;
    private BufferedImage[] imageCache = new BufferedImage[IMAGE_CACHE_SIZE];
    private int imageCacheIndex = 0;
    * Creates an <code>ImageFill</code> that draws <i>image</i>
    * scaled to fit the <code>paintFill</code> rectangle
    * parameters.
    * @see #getImage
    * @see #paintFill
    public ImageFill(BufferedImage image)
    this.image = image;
    * Creates an "empty" ImageFill. Before the ImageFill can be
    * drawn with the <code>paintFill</code> method, the
    * <code>image</code> property must be set.
    * @see #setImage
    * @see #paintFill
    public ImageFill()
    this.image = null;
    * Returns the image that the <code>paintFill</code> method draws.
    * @return the value of the <code>image</code> property
    * @see #setImage
    * @see #paintFill
    public BufferedImage getImage()
    return image;
    * Set the image that the <code>paintFill</code> method draws.
    * @param image the new value of the <code>image</code> property
    * @see #getImage
    * @see #paintFill
    public void setImage(BufferedImage image)
    this.image = image;
    for (int i = 0; i < imageCache.length; i++)
    imageCache[i] = null;
    * Returns the actual width of the <code>BufferedImage</code>
    * rendered by the <code>paintFill</code> method. If the image
    * property hasn't been set, -1 is returned.
    * @return the value of <code>getImage().getWidth()</code> or -1 if
    * getImage() returns null
    * @see #getHeight
    * @see #setImage
    public int getWidth()
    BufferedImage image = getImage();
    return (image == null) ? -1 : image.getWidth();
    * Returns the actual height of the <code>BufferedImage</code>
    * rendered by the <code>paintFill</code> method. If the image
    * property hasn't been set, -1 is returned.
    * @return the value of <code>getImage().getHeight()</code> or -1 if
    * getImage() returns null
    * @see #getWidth
    * @see #setImage
    public int getHeight()
    BufferedImage image = getImage();
    return (image == null) ? -1 : image.getHeight();
    * Create a copy of image scaled to width,height w,h and
    * add it to the null element of the imageCache array. If
    * the imageCache array is full, then we replace the "least
    * recently used element", at imageCacheIndex.
    private BufferedImage createScaledImage(Component c, int w, int h)
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    BufferedImage newImage = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
    boolean cacheOverflow = true;
    for (int i = 0; i < imageCache.length; i++)
    Image image = imageCache;
    if (image == null)
    imageCache[i] = newImage;
    cacheOverflow = false;
    break;
    if (cacheOverflow)
    imageCache[imageCacheIndex] = newImage;
    imageCacheIndex = (imageCacheIndex + 1) % imageCache.length;
    Graphics g = newImage.getGraphics();
    int width = image.getWidth();
    int height = image.getHeight();
    g.drawImage(image, 0, 0, w, h, 0, 0, width, height, null);
    g.dispose();
    return newImage;
    * Returns either the image itself or a cached scaled copy.
    private BufferedImage getFillImage(Component c, int w, int h)
    if ((w == getWidth()) && (h == getHeight()))
    return image;
    for (int i = 0; i < imageCache.length; i++)
    BufferedImage cimage = imageCache[i];
    if (cimage == null)
    break;
    if ((cimage.getWidth(c) == w) && (cimage.getHeight(c) == h))
    return cimage;
    return createScaledImage(c, w, h);
    * Draw the image at <i>r.x,r.y</i>, scaled to <i>r.width</i>
    * and <i>r.height</i>.
    public void paintFill(Component c, Graphics g, Rectangle r)
    if ((r.width > 0) && (r.height > 0))
    BufferedImage fillImage = getFillImage(c, r.width, r.height);
    g.drawImage(fillImage, r.x, r.y, c);
    </code>
    Now it's just a simple matter of creating a frame and making the frame panel the frame's content pane:
    <code>
    import java.awt.BorderLayout;
    import java.awt.HeadlessException;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    public class ImageFrame extends JFrame
    private FramePanel framePanel;
    //start of constructors
    public ImageFrame() throws HeadlessException
    super();
    init();
    public ImageFrame(String title) throws HeadlessException
    super(title);
    init();
    // end of constructors
    void init()
    try
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch (Exception e)
    System.out.println ("Unknown Look and Feel");
         framePanel = new FramePanel();
         this.getContentPane().add(framePanel, BorderLayout.CENTER);
         this.setContentPane(framePanel);
         ((JPanel)this.getContentPane()).setOpaque(false);
    </code>

  • How to copy images from another MC in reversed order??

    Hi everyone,
    I'm new to AS3 and have been fighting and searching for a solution to this problem for a week now, and I'm VERY close!
    I crated a MC holding of a series of images (about 50) and I jump around in it using plenty AS3 scripts (most of which I don't fully understand yet, but I'm working on that to! )
    I had to find a way to "rewind" (= play backwards) the MC. Since there is a stop(); command in almost every frame, prevFrame does not work and if I put that in a loop, it goes WAY to fast (but worked).. So I could think of only one way...
    Create a new (reverserd) MC with the same image sequence ald reverse it manually and play that one.
    This all works fine (very proud of it ).
    Now my question:
    To get this to work for multiple image sequences, I have to load all images twice (once in MC_1 and again in MC_2 and select them and reverse them).
    Not a big one, unless you want to create MANY of those SWF's...
    Is it possible to load the 50 images of the first MC in reverse into the second MC dynamically? JUST the images, noting else.
    extra info: the MC_2 is already in the lib(empty) and placed on the stage.
    something like:
    var pointer:Number=1;
    for (var:i:Number=50;i>=0;i--) {
    get MC_1.picure(var);
    put it in MC_2.frame(pointer);
    pointer = pointer + 1;
    All help is welcome and please take into account that I have little experience and copy most of my scripting from people like you
    T.I.A.
    Melluw

    I tried your advice (thanks for that)
    The event I already have is the mouse leave
    I //-d out the part I removed (what did work)
    The code I ended up with is:
    function Start() {
    stage.addEventListener(Event.MOUSE_LEAVE, cursorHide);
    function cursorHide(evt:Event):void {
    var currFrame = MC_1.currentFrame;
    if (CCW == true) {  //it is true in this case
      movStart = (50 - currFrame);
    else {
      movStart = currFrame;
    if (movStart>25) {
      MC_1.prevFrame();
    // removed swapChildren(MC_1, MC_2); // This is the part I removed
    // removed MC_2.gotoAndPlay(movStart);
    else {
      MC_1.gotoAndPlay (movStart);
    And if I leave the stage on the part where movStart is indeed >25
    Nothing happens,
    So I guess this is not what you meant
    Subject: Action Script 3 how to copy images from another MC in reversed order??
    I cannot direct you in the loading of the images approach, it will be too complicated, and will probably not work anyways... when you move away from a frame that has dynamic content, you lose the content.  So basically, there is nothing practical in taking that approach.
    I do niot understand what the problem will be with the enterFrame/prevFrame approach. If everything you can do with the mouse is already used (which I doubt) by the first mc, then there is nothing else you can do with this file.  You probably just need to rethink your control scheme.  You should search Google for "AS3 slideshow tutorial", and to lighten up your design, add "XML" in that search.
    >

  • Adobe Reader 9 Mac - cannot copy images

    I upgraded to Reader 9, and another person in our office is using 8 with the same problem. We can no longer copy images out of a PDF - when we try to paste an image that appeared to be copied we only get a gray box. We've tried many ways including pasting directly into Word or Excel, choosing 'New from Clipboard' in Photoshop Elements, creating a blank Photoshop file and pasting, etc. This has works perfectly in Acrobat 5.0 and in Reader 7.0.5 (which I have gone back to using - I'm sure glad I waited before removing it from my system!).
    Any thoughts?

    (Gary_Roger) wrote:
     I was wrong on both counts. With the help of the local Apple store, I found a solution. First, I Moved to Trash all adobe related files/folders from /Users/*myaccount*/Library/Cache and /Users/*myaccount*/Library/Preferences. When I started "Adobe Reader 9", I at least got the license agreement but again it failed with an "internal error". I then moved the /Users/*myaccount*/Library/Application Support/Adobe folder to my desktop. I was then able to start "Adobe Reader 9" successfully.
    I was having the "Internal Error" message on all my repeated installs of Reader in Mac OS 10.6 ("Snow Leopard") and this fixed it for me. The only thing I did different, was after the app finally launched without an error, I dragged all the non-Acrobat Reader folders inside of /Users/*myaccount*/Library/Application Support/Adobe back to the folder. I then re-launched Reader just to check and all was fine.
    Thanks! This fixed my Adobe Reader on Snow Leopard problem.

  • I can`t copy image from the web sites to Microsoft Word, since I update firefox ! Why ? How I can fix it ???

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/939085]]</blockquote>
    I am tryin to copy image form ZABBIX to Word document. Everything was fine before update and now I am having a problem

    More generally, when you have a problem with one particular site, a good "first thing to try" is clearing your Firefox cache and deleting your saved cookies for the site.
    (1) Bypass Firefox's Cache
    Use Ctrl+Shift+r to reload the page fresh from the server.
    (You also can clear Firefox's cache completely using:
    orange Firefox button ''or'' Tools menu > Options > Advanced
    On the Network mini-tab > Cached Web Content : "Clear Now")
    (2) Remove the site's cookies (save any pending work first) using either of these:
    While viewing a page on the site:
    * right-click and choose View Page Info > Security > "View Cookies"
    * Alt+t (open the classic Tools menu) > Page Info > Security > "View Cookies"
    Then try reloading the page. Does that help?

  • Background image  for JPanel using UI Properties

    Is there any way to add background image for JPanel using UI Properties,
    code is
    if (property.equals("img")) {
    System.out.println("call image file in css"+comp);
    //set the background color for Jpanel
    comp.setBackground(Color.decode("#db7093"));
    here the comp is JPanel and we are setting the background color,
    Is there any way to put the Background image for the JPanel ????

    KrishnaveniB wrote:
    Is there any way to put the Background image for the JPanel ????Override the paintComponent(...) method of JPanel.
    e.g.
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    public class ImagePanel {
        public void createAndShowUI() {
            try {
                JFrame frame = new JFrame("Background Image Demo");
                final Image image = ImageIO.read(new File("/home/oje/Desktop/icons/yannix.gif"));
                JPanel panel = new JPanel() {
                    protected void paintComponent(Graphics g) {
                        g.drawImage(image, 0, 0, null);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(new Dimension(400, 400));
                frame.setContentPane(panel);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            } catch (IOException ex) {
                ex.printStackTrace();
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new ImagePanel().createAndShowUI();
    }

  • Displyaing image in JPanel

    I am using below code to display image in jpanel.
    It is not displaying image. Please help me.
    import java.util.Vector;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Toolkit;
    import java.awt.Image;
    public class project extends JPanel {
         public void init()
              JFrame mFrame = new JFrame("Documentum Login");
              mFrame.setSize(350,200);
    //mFrame.setResizable(false);
    Dimension dim = getToolkit().getScreenSize();
    mFrame.setLocation((dim.width/2) - (mFrame.getWidth()/2),(dim.height/2) - (mFrame.getHeight()/2));
              //JPanel hpan = new JPanel();
    //hpan.setLayout(new BoxLayout(hpan,BoxLayout.Y_AXIS));
    //hpan.setBorder(new TitledBorder (new LineBorder (Color.blue, 1)));
              //Image img = Toolkit.getDefaultToolkit().getImage("D:/Temp/test.jpg");
              ImageIcon icon = new ImageIcon("D:\\Temp\\test.jpg");
              JLabel imageLabel = new JLabel(icon);
              JScrollPane scrollPane = new JScrollPane (JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              scrollPane.getViewport().add(imageLabel);
              JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              panel.add(scrollPane,BorderLayout.CENTER);
              mFrame.getContentPane().add(panel);
    mFrame.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e) {System.exit(0); }
    mFrame.setVisible(true);
         public static void main(String args[])
              project pr = new project();
              pr.init();          
    }

    Don't add() to a JViewport, setView() instead.

  • How do I copy image from web and paste into Open Office Document

    Whenever I choose Copy Image from Safari and then paste into open office, I only get the image url and not the image. I am sure that I am not selecting Copy Image Address.
    When I copy images from my iTunes album artwork and paste into open office it works fine.
    Any thoughts?

    I have done the same thing using Firefox and it works just fine. It seems to be an issue with Safari.

  • How do i copy images from the web?

    How do I copy images on the web for use in a powerpoint presentation?

    Drag them to the desktop or control-click them and choose to copy them to the clipboard.
    (61484)

  • Can't copy image/video from Nok 5800 XM to PC

    Owh...i have no idea again....... i've tried many ways, but the files are failed to be copied, i've tried by using nok pc suite&mass storage mode to transfer them, but it's always failed. it seems that the files i copy are corrupted or uncompleted. let say,,,i want to copy image(400 KB), but the result in my PC is only 5 KB, so i can't open it. but when i copied files from other phone(nok 7610&N70),it's no problem, i can do it by pc suite or mass storage mode,,,,, Anyone can help me please...............

    Pl. do not start duplicates..
    refer your other thread under Nseries & Smartphones...
    --------------------------------------------------​--------------------------------------------------​--------------------------------------------------​--If you find this helpful, pl. hit the White Star in Green Box...

  • Display a transparent image in JPanel

    i just start using Java Graphics Programming fews month ago. there's some problem i facing recently. i doing a simple gif file viewer. first i get the file using the Toolkit and put it in a Image object and use the Gif Decoder to decoded each frame of the Gif File to BufferedImage object and display each of the frame in a JPanel inside a JFrame.My porblem is :-
    How to display a transparent image in JPanel? my image source in BufferedImage and how to i know the image is transparent or not?

    I simply use ImageIcon object to display the image (*.gif,*.jpg)
    JLabel l=new JLabel(new ImageIcon("file path"));
    add the label to a panel or frame or dialog
    this object no need to use the ImageBuffered Object
    It can display any animate gif whether the background is transparent or not.

  • Having trouble displaying image in JPanel

    I want to display an image in jpanel making it to scale to the size of the panel.
    And later i should be able to draw on that image , i am really new to all this , but i have to finish it soon.
    This is the code i am compiling and getting error
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class LocaterClient extends JFrame
         JPanel panel;
         public LocaterClient()
              super("LocaterClient");
              panel = new JPanel();
              panel.setSize(374,378);
              panel.setOpaque(false);
              panel.setVisible(true);
         getContentPane().add(panel);
         /*JFrame f = new JFrame();
         f.setSize(374,378);
         f.getContentPane().add(panel);*/
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              ImageIcon img = new ImageIcon("World_MER.jpg");
              ImageIcon fillImage = new ImageIcon(img.getImage().getScaledInstance
    (getWidth(), getHeight(),Image.SCALE_REPLICATE));
              g.drawImage(fillImage.getImage(), 0,0, this);
         public static void main(String args[])
              LocaterClient lc = new LocaterClient();
              lc.setDefaultCloseOperation( EXIT_ON_CLOSE );
              lc.pack();
              lc.setVisible(true);
    This is the error i am getting
    LocaterClient.java:24: cannot resolve symbol
    symbol : method paintComponent (java.awt.Graphics)
    location: class javax.swing.JFrame
    super.paintComponent(g);
    ^
    1 error
    If i remove super.paintComponent(g); line it compiles and runs but i get a tiny panel without the image.
    PLease help me , i am not evn sure is this is the procedure should i follow , because i should be able to draw on that image later on .
    Please provide me with some sample code.

    import javax.swing.*;
    import java.awt.*;
    public class ImagePainter extends JPanel{
      private Image img;
      public ImagePainter(){
        img = Toolkit.getDefaultToolkit().getImage("MyImage.gif");
      public void paintComponent(Graphics g){
        g.drawImage(img,0,0,getSize().width,getSize().height);
      public static void main(String[]args){
        JFrame frame = new JFrame();
        frame.getContentPane.add(new ImagePainter());
        frame.setSize(500,500);
        frame.show();

  • Can I copy images from Album to Album

    Can I "copy" images from Album to Album and then expect to be able to export that data into Keynote?
    I put copy in quotes because I am such a new user I am not even sure at this point when I am copying or moving images as opposed to pointers.
    But the bottom line is that I need to know if I can use the data in Albums that I see images in for a presentation.
    Thanks.

    Aperture 3 does have a few things that work in different ways than Ap2, but dragging images to albums is the same. Cut/copy has never been a feature. It works in a different way. Allan

  • Displaying DICOM images in JPanel

    Can anyone please tell me how to display DICOM images using JPanel? I can use JPanel to display ordinary images but it does not seem to work using DICOM images. Can anyone please help me out? I've spent hours and hours trying to solve this problem. Thank you in advance.

    Can anyone please tell me how to display DICOM images
    using JPanel? I can use JPanel to display ordinary
    images but it does not seem to work using DICOM
    images. Can anyone please help me out? I've spent
    hours and hours trying to solve this problem. Thank
    you in advance.The JPanel is only able to display JPEG and GIF images, you will need to decode the DICOM image first and convert to JPEG or GIF format, there are some source codes available on the net. Also check this link out
    http://www.dclunie.com/medical-image-faq/html/part8.html

  • How do I copy images to buffer in Vision Builder Eval

    I have an evaluation copy of Vision Builder.
    I want to load images from files and do an image divide, yet when I copy images to the buffers, the buffers remain empty. Help!

    It sounds like you're using the Vision Builder AI eval and launching the Image Assistant tool to process your image. Buffers in the Image Assistant don't carry over to other steps. However, in one session of Image Assistant you should be able to save an image to a buffer and retrieve it in the same session. If this is not the case, then you should go to ni.com/ask to get in touch with an NI Applications Engineer.
    Kyle V

Maybe you are looking for