Results 1 to 3 of 3
  1. #1
    The_Duke is offline Member
    Join Date
    Dec 2014
    Posts
    2
    Rep Power
    0

    Question How to create draggable image?

    Hi there guys and gals! I'm new to NetBeans, so i have this problem:
    I want to create a project that when you select item from a Combo Box it will display a picture, but, picture that can be moved all over the panel. I cant find solution for that... Anyone could help? Thanks in advance, The_Duke!
    And, i forgot to tell, every image on the panel should be movable...
    And, I'm using NetBeans IDE 8.0.2
    Last edited by The_Duke; 12-24-2014 at 09:09 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to create draggable image?

    First, that is not a NetBeans problem. That is a Java problem. So here is how you do it.


    1. Create a JComboBox to reference several images
    2. Select an image and draw it somewhere on a JPanel.
    3. Implement a mouse listener to intercept MouseMotionEvents and MouseEvents
    4. When the mouse is clicked and dragged, check to see if the mouse is within the area where you drew the picture.
    5. As you drag the mouse, redraw the picture relative to the mouse position.


    Do do this you need to understand about mouse listeners, JComboBoxes and working with images. All of those are covered in the Java Tutorials in my signature. Once you get your code written, the forum can assist with any problems you may have.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    The_Duke is offline Member
    Join Date
    Dec 2014
    Posts
    2
    Rep Power
    0

    Default Re: How to create draggable image?

    Quote Originally Posted by jim829 View Post
    First, that is not a NetBeans problem. That is a Java problem. So here is how you do it.


    1. Create a JComboBox to reference several images
    2. Select an image and draw it somewhere on a JPanel.
    3. Implement a mouse listener to intercept MouseMotionEvents and MouseEvents
    4. When the mouse is clicked and dragged, check to see if the mouse is within the area where you drew the picture.
    5. As you drag the mouse, redraw the picture relative to the mouse position.


    Do do this you need to understand about mouse listeners, JComboBoxes and working with images. All of those are covered in the Java Tutorials in my signature. Once you get your code written, the forum can assist with any problems you may have.

    Regards,
    Jim
    Thank you Jim!

Similar Threads

  1. Trying to input Draggable boxes
    By Nindustries in forum New To Java
    Replies: 2
    Last Post: 12-27-2012, 01:16 PM
  2. create image from canvas
    By mitra in forum Java Applets
    Replies: 11
    Last Post: 08-20-2011, 01:23 PM
  3. JToolBar make it non-draggable
    By nathic in forum New To Java
    Replies: 1
    Last Post: 03-22-2011, 08:52 AM
  4. Replies: 3
    Last Post: 07-14-2010, 10:34 PM
  5. Canvas with draggable window
    By shravan28 in forum SWT / JFace
    Replies: 1
    Last Post: 03-24-2009, 07:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •