Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: How to copy image from one jpanel to another jpanel

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up How to copy image from one jpanel to another jpanel

    Hai! I am new to java. In my swings application a problem was arised. that is when i drag an image from one jpanel to another jpanel. the copy of the image will come with the mouse. the original image may not move. only copy of the image will move from one jpanel to another. here is the sample code. how to move the copy of the image from one jpanel to another jpanel.
    Please help me.

    import javax.swing.*; 
    import java.awt.*; 
    public class test1 { 
     public test1() {
      JFrame frame=new JFrame("Drag");
      Container container=frame.getContentPane();
      JPanel panel=new JPanel(new GridLayout(2,1));
      JPanel panel1=new JPanel(new BorderLayout());
      JPanel panel2=new JPanel();
      JLabel label=new JLabel(new ImageIcon("icons/save.png"));
      panel1.add(label);
      panel1.setBackground(Color.red);
      panel2.setBackground(Color.gray);
      panel.add(panel1);
      panel.add(panel2);
      container.add(panel);
      frame.setSize(300,400);
      frame.setVisible(true);
     }
     /**
     * @param args
     */
     public static void main(String[] args) {
      new test1();
     }
    }
    Last edited by helloworld922; February 15th, 2010 at 11:59 AM.


Similar Threads

  1. need help with ActionListener,JPanel,JFrame
    By amahara in forum AWT / Java Swing
    Replies: 5
    Last Post: February 3rd, 2010, 01:40 PM
  2. Drawing image on JPanel from another frame
    By jeryslo in forum AWT / Java Swing
    Replies: 3
    Last Post: December 8th, 2009, 04:01 PM
  3. How to write above a JPanel
    By bruno88 in forum AWT / Java Swing
    Replies: 4
    Last Post: June 23rd, 2009, 06:16 PM
  4. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM
  5. Replies: 4
    Last Post: May 27th, 2008, 01:20 PM