Multiple Images Dragged on a JPanel

I am trying to add multiple BufferedImages to a JPanel. I can get one BufferedImage on there fine by creating my own class which overrides JPanel, and then in the paintComponent(Graphics g) method, I have a method with g.drawImage(image, npx, npy, null); to draw the image on the panel.
So that works fine for one image. I have also implemented a MouseMotionAdapter so I can drag the image around. However I am having GREAT difficulty implementing it with multiple images. I cannot workout how to do this. I am aware I need to have an ArrayList containing all the images, but I cannot determine how I am to loop through each one, getting the correct image, then moving that one.
Please help with some useful code. (I can provide mine if required).
Kelvin

803539 wrote:
Hi pierrot_2,
I'm not yet. I'm not yet, I was thinking I would just have to loop through the list of images, getting the correct image (by a method unknown yet) and then calling the drawImage() method, passing the selected image as a parameter.Kelvin, take your project one step at a time. The first thing I would do is try painting all four images first. You can do it quickly by having a Point[] array along side of a BufferedImage[] array. Lets's say the images are w=200, h=160 for now.
BufferedImage[] images = new BufferedImage[4];
Point[] locations = new Point[4];
locations[0] = new Point(0, 0);
locations[1] = new Point(200, 0);
locations[2] = new Point(0, 160);
locations[3] = new Point(200, 160);
// paintComponent
for(int i = 0; i < images.length; i++)}
  BufferedImage bi = images;
Point p = locations[i];
g.drawImage(bi, p.x. p.y, null);
}Use something like the code above to get you started. Kelvin, there are much better ways to do this, but for now see if you can paint all your images on the JPanel first, using nothing but <tt> images </tt>and<tt> locations </tt>as described. Later, you may want to switch to Rectangles. See how the FOR loop will call<tt> drawImage() </tt>four times. See how the Point objects are being used to position the image being painted? Do this BEFORE you try to move them around the canvas. Call home if you have troubles.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Which Listener I should use if I drag and Drop an image/icon into a JPanel?

    Dar Friends:
    Happy new year.
    I try to drag and Drop an image/icon into a JPanel, and hope I can immediately detect it after DND,
    Which Listener I should use in this JPanel if I drag and Drop an image/icon into a JPanel??
    Thanks

    Thank camickr .
    I can dnd an image into a JPanel called JPanelOld already, I hope to use another JPanel or JTree to listen to any Dropped Image in JPanelOld later on so I can take some action in another JPanel or JTree.
    so what kind of Listener I should use for my purpose??
    where to add this Listeners??
    Happy New Year.

  • Drag and drop or place multiple images

    Hi,
    I'm working with Photoshop Elements 12 and would like to place multiple images (on different layers) in my project but am only able to place one image with the option "place" at a time. Is there a way to place multiple images at once?
    Other option that works in Photoshop is drag and drop mutliple files from my finder window (I'm a MAC user) into the open project. This would create multiple new layers with the imported files. This doesn't work for me with Photoshop Elements 12. When I drag and drop, new projects are created with the imported files.
    Hope someone has an answer for this. Thanks!

    Thanks LarryHN thats helpful. I've just tried that and the export 'current' option does indeed re-create the edited photo file with exactly the same file size at that shown in iPhoto. I did consider the 'current' option but was put off by the loss of the metadata with this option. But maybe the old drag and drop approach was the same?
    It's curious that the resulting file size from 'export, current' is different (larger in the example I just tried) in comparison to that resulting from 'export, jpeg' (with either the medium or high option selected).
    OK there seems to be a couple of reasonable options available although neither is as nice as the simple 'drag and drop' which used to be available!!! Why would they remove that option?? (and yet not for single files?).
    Thanks
    Tom

  • Can we attach multiple images to a pages document in one go rather than drag and drop in to a media placeholder?

    Can we attach multiple images to a pages document in one go rather than drag and drop in to a media placeholder?

    Danny Spry wrote:
    Can we attach multiple images to a pages document in one go rather than drag and drop in to a media placeholder?
    Danny,
    Sure you csn. Don't be afraid to try this kind of stuff for yourself. If things don't work out, just Command-Z your way back to the previous state. In this case it should work just great. Once your multiple selection appears in Pages, click off the selected new objects to de-select them, then select them one at a time for positioning.
    Jerry

  • Trying to create a surface  with multiple images with mouse events

    novice programmer (for a applet program)
    hi trying to create a surface i.e jpanel, canvas, that allows multiple images to be created.
    Each object is to contain a image(icon) and a name associated with that particular image. Then each image+label has a mouse event that allows the item to be dragged around the screen.
    I have tried creating own class that contains a image and string but I having problems.
    I know i can create a labels with icons but having major problems adding mouse events to allow each newly created label object to moved by the users mouse?
    if any one has any tips of how to acheive this it would be much appreciated. Thanks in advance.
    fraser.

    This should set you on the right track:- import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        public class DragTwoSquares extends JApplet implements MouseListener, MouseMotionListener {  
           int x1, y1;   // Coords of top-left corner of the red square.
           int x2, y2;   // Coords of top-left corner of the blue square.
           /* Some variables used during dragging */
           boolean dragging;      // Set to true when a drag is in progress.
           boolean dragRedSquare; // True if red square is being dragged, false                              //    if blue square is being dragged.                            
           int offsetX, offsetY;  // Offset of mouse-click coordinates from
                                  //   top-left corner of the square that was                           //   clicked.
           JPanel drawSurface;    // This is the panel on which the actual
                                  // drawing is done.  It is used as the
                                  // content pane of the applet.  It actually                      // belongs to an anonymous class which is
                                  // defined in place in the init() method.
            public void init() {
                 // Initialize the applet by putting the squares in a
                 // starting position and creating the drawing surface
                 // and installing it as the content pane of the applet.
              x1 = 10;  // Set up initial positions of the squares.
              y1 = 10;
              x2 = 50;
              y2 = 10;
              drawSurface = new JPanel() {
                        // This anonymous inner class defines the drawing
                        // surface for the applet.
                    public void paintComponent(Graphics g) {
                           // Draw the two squares and a black frame
                           // around the panel.
                       super.paintComponent(g);  // Fill with background color.
                       g.setColor(Color.red);
                       g.fillRect(x1, y1, 30, 30);
                       g.setColor(Color.blue);
                       g.fillRect(x2, y2, 30, 30);
                       g.setColor(Color.black);
                       g.drawRect(0,0,getSize().width-1,getSize().height-1);
              drawSurface.setBackground(Color.white);
              drawSurface.addMouseListener(this);
              drawSurface.addMouseMotionListener(this);
              setContentPane(drawSurface);
           } // end init();
           public void mousePressed(MouseEvent evt) {
                  // Respond when the user presses the mouse on the panel.
                  // Check which square the user clicked, if any, and start
                  // dragging that square.
              if (dragging)  // Exit if a drag is already in progress.
                 return;           
              int x = evt.getX();  // Location where user clicked.
              int y = evt.getY();        
              if (x >= x2 && x < x2+30 && y >= y2 && y < y2+30) {
                     // It's the blue square (which should be checked first,
                     // since it's in front of the red square.)
                 dragging = true;
                 dragRedSquare = false;
                 offsetX = x - x2;  // Distance from corner of square to (x,y).
                 offsetY = y - y2;
              else if (x >= x1 && x < x1+30 && y >= y1 && y < y1+30) {
                     // It's the red square.
                 dragging = true;
                 dragRedSquare = true;
                 offsetX = x - x1;  // Distance from corner of square to (x,y).
                 offsetY = y - y1;
           public void mouseReleased(MouseEvent evt) {
                  // Dragging stops when user releases the mouse button.
               dragging = false;
           public void mouseDragged(MouseEvent evt) {
                   // Respond when the user drags the mouse.  If a square is
                   // not being dragged, then exit. Otherwise, change the position
                   // of the square that is being dragged to match the position
                   // of the mouse.  Note that the corner of the square is placed
                   // in the same position with respect to the mouse that it had
                   // when the user started dragging it.
               if (dragging == false)
                 return;
               int x = evt.getX();
               int y = evt.getY();
               if (dragRedSquare) {  // Move the red square.
                  x1 = x - offsetX;
                  y1 = y - offsetY;
               else {   // Move the blue square.
                  x2 = x - offsetX;
                  y2 = y - offsetY;
               drawSurface.repaint();
           public void mouseMoved(MouseEvent evt) { }
           public void mouseClicked(MouseEvent evt) { }
           public void mouseEntered(MouseEvent evt) { }
           public void mouseExited(MouseEvent evt) { }  
        } // end class

  • Is there a way to add multiple images at the same time to Keynote 6.0?

    I just brought keynote after searching online about adding multiple images to a presentation all in one go - I couldn't do this on the powerpoint version I was using but there were multiple references on google to being able to do this on keynote. I purchased it and now can't get it to work! Any ideas anyone? Thanks

    Do you mean like dragging in multiple images and having one image go on each slide? If so, you just drag the images into the Slide List on the left instead of onto the slide. From this prior post.
    https://discussions.apple.com/message/9068283#9068283

  • Cannot select multiple images in iPhoto '08?

    What am I doing wrong? I want to select multiple images to either print several on a page, or publish to a gallery, but for the life of me I cannot find a view which shows me all photo thumbnails or all thumbnails in an album or all in an event. I can spin the mousewheel to singly go through them, or I can hit edit and go to full screen where I get a thumbnail bar and can select multiples and view them at the same time, but printing or publishing this selection only recognizes the first photo as selected. If I try to select View>Thumbnails, the subsequent menu options are grayed out, and the top one is "hide" even though I see no thumbnail bar. Is there something very obvious I'm missing, or has something gone awry and I should reinstall?
    <Edited by Host>
    Any one can help them?
    Thanks

    There's a slider down right of the iPhoto Window - drag it left.
    Regards
    TD

  • How can you find out an individual image size from multiple images on a canvas

    This is probably a really really simple question but I can't for the life of me find how I can find out an individual image size from multiple images on a canvas. eg I have 3 photos i want to arrange 1 large and the other two next to it half the size. How can I edit individual image size on the canvas as when I select the image on a sperate layer I want to resize it just resizes the entire canvas and not the individual image
    Thanks

    I want to know they exact dimensions though. You can get them by dragging to the 0,0 corner and then reading off of the ruler scale on the sides but its fiddily as you have to zoom right in and work it out. I know in photoshop there is a ruler but is there any other way in Elements?

  • InDesign CS3 Scripting XML Import Multiple Images into same Text Frame

    I am having trouble importing multiple images into the same Text Frame using XML import. I imported 5 images into the text frame. However, all 5 images are laying on top of one another. Does anyone know if there is a way to have all images laying out like how Microsoft Word handles inline images, i.e., laying out next image to the right of previsous image in the same line and if there is not enough space left in the line, then wrap to next line. Thanks in advance. I understand I could use JavaScript to do post import processing, e.g, calculate the image size and place each images accordingly. But I am trying to see whether there is a way to do this without scripts.

    You can apply an object style to all anchored images by script. A text frame containing main flow should be selected.
    var doc = app.activeDocument;
    var textFrame =  app.selection[0];
    var rectangles = textFrame.texts[0].rectangles;
    if (rectangles.length > 0) {
         for (var i=0; i < rectangles.length; i++) {
              rectangles[i].appliedObjectStyle = doc.objectStyles.item("Cover");
    However, there is a better approach:
    Step 1
    Create place holders for a single "Book" element and format it as needed -- apply an object style to the cover.
    Step 2
    Import the xml file -- the placeholders are replaced with data from the 1st xml element
    Step 3
    Drag & drop the element containing all "Books" elements into the main flow -- all elements are placed and formatted the same way as in step 1.
    Finally, add a new page, click the overset text icon and autoflow text to add pages so that to fit all the text.
    Hope this helps.
    Kasyan

  • How to move multiple images in lr at one time from one subfolder to the next?

    How would i accomplish this procedure in lr5. I know you can click on an image  and drag it to the target folder.  But for multiple images this is the ? Thanks!!

    Same as you would do it in your operating system.
    You select multiple images (click, ctrl-click, ctrl-click, etc., or click on one image and then shift-click on another image to select the entire sequence) and then drag.
    Of course, you might also want to simplify your life and develop a workflow where you don't have to move photos from here to there by using keywords instead of folders to organize.

  • Lightbox with multiple images attached to one thumbnail?

    Is it possible to have one thumbnail allow you to scroll through multiple images without having to click on another thumbnail? 
    For example,  lets say that I have three projects with 10 images per project.  I only want to have three thumbnails which will allow the user to see each project by clicking on it's "master" thumbnail.
    Thanks.

    If your intent is to have a single thumbnail (image) that your visitors click and it launches a Lightroom with Slideshow, you can try the following.
    The gist :
    Insert Slideshow Widget into target of Composition Widget
    The details :
    01. Drag & drop the Lightroom Display Composition Widget onto your design surface.
    02. Drag & drop a Slideshow Widget into (this is the important bit) the Target of the Lightroom Display Composition Widget
    The Target is the large area of the Composition Widget
    The Target is what appears as a light box when you click on the Trigger (the smaller boxes)
    03. Add your thumbnail image to the Trigger of the Lightroom Display Composition Widget (the smaller boxes)
    Style it :
    You're now ready, style your widgets and replace the images of the Slideshow Widget and you'll have the effect you're looking for.
    Very crude example :
    http://slideshowwidgetincompositionwidget.businesscatalyst.com/index.html

  • I am trying to import photo's on i photo.  It downloads all of the pictures on my camera, how do i only select the photos i want?  Is there a way to do this without selecting one photo at a time? is there a way to select multiple images?  thanks!

    I am trying to import photo's on i photo.  It downloads all of the pictures on my camera, how do i only select the photos i want?  Is there a way to do this without selecting one photo at a time? is there a way to select multiple images?  thanks!

    To select consecutive images click and drag the cursor over multiple thumbnails to select all at once.
    To select multiple images that are randomly located hold down the Command(⌘) key and click on those images you want to select.
    Or to select consecutive images from a list of images that are together hold down the Shift key and and click on the first photo you want to select and the on the last photo you want in the list.
    OT

  • Aperture cannot add GPS data to multiple images at the same time

    I am new to Aperture and have been using it for a week or so now. Today I tried to add GPS data to a number of images and found out, it appears Aperture can only add GPS data to one image at the time. When I select multiple images to add the GPS data to, it just doesn't do anything. It leaves the GPS data blank.
    Here is what I do:
    From the Info-tab I select "GPS" from the drop down menu
    At the bottom of the info tab I show the map
    In the map's search box I enter the location I want to assign to the photo(s)
    From the resulting drop down menu I select the locatiion I want and press the "assign to location" button
    As long as I choose only a single image, this works fine and the GPS Data is added. Not so when I select more than a single image. After pressing the "assign to location" button it seems as if the GPS data is added (there is no message indicating otherwise), but the GPS data in the selected images is blank.
    What am I doing wrong ?
    Additional info
    I have been testing this a bit more and the behavior is even more strange: When you select multiple images in Aperture, they get a thin white border, except the one that you touch last (normally the last image of the selection) that will have a thicker border around it. It appears that, when selecting multiple images, the GPS data is ONLY assigned to the photo in the selected setthat has the thicker border (?????)
    Message was edited by: dinky2

    Rereading your post, I think the problem is, that you are assigning the location from the Info panel and not from the Metadata menu. The Info panel and the Metadata menu ar behaving differently.
    The Info panel will always only affect the primary selection, but the Metadata menu will work on all selected images (unless "Primary only" is checked). So , if you want to assign your location to multiple images, use "Metadata > Assign location" instead of the little map in the "Info" panel.
    Or use the "Places" view. Then you can drag all images at once to the same pin on the map.
    Regards
    Léonie

  • Keywording multiple images

    Aperture is making me crazy. As soon as I ressolve on problem (usually with a workaround rather than a solution) another one pops up. Today it's about keywording multiple images.
    The manual says I can select a group of images and drag a keyword from the Keyword HUD to apply it to all of the images. But, it doesn't happen. I'm looking at 500 or so images that need multiple keywords applied to them all, but Aperture will only apply the keyword to one image no matter how many I have selected. Surely this cannot be right, but no matter what I do I seem to be able to apply a keyword to only one image at a time.
    I purely hat this application. Hate, hate, hate, hate. Been trying to develop a usable workflow for weeks and it's just not happening.

    Well, I have a bunch of cameras, and I also do photo restorations (typically pre 1900) for local families out here in the wilderness. The camera that is on my hip all day is just a little Canon A1100 IS, and the JPEGs it produces rarely need anything that Aperture can't handle. I have a couple of Nikons that I use locally, but the really problematic camera that I use a lot is a Fuji HS10. I'm too old to be lugging lenses and heavy bodies up and down mountains, and I frequently find myself on a ledge with a 100 to 1000 foot drop off and not enough room to put both feet side by side. The camera makes a decent picture, but noise is an issue as is lens correction.
    The workflow from this camera that I would prefer to use is that I would like to import RAW images directly from the camera into Aperture, naming the project on import. Can't do that because while Adobe supports RAW from this camera, Apple doesn't. So I copy the images from the card to the desktop and run them through DNG Converter.
    Then I import into Aperture as a project.
    At this point I would prefer to set the white balance in Aperture and open as a TIFF in Camera RAW for Lens Correction and Noise Reduction. Maybe some color correction and exposure stuff too, but that could as easily be done in Aperture.
    Then into Photoshop for more accurate color correction, sharpening and whatever else is necessary. Then I'd like to save it back into Aperture as a TIFF and have Aperture automagically select the last edited version in the stack as the pick and keep the stack closed so the last edited version is all I ever see.
    Unfortunately, this breaks down in several places. The biggest is that if I have PS open the TIFF in Camera Raw it breaks the connection to the file in Aperture, so when I save out of Photoshop it is treated as a Save As. Apple appears to insist on a .tiff extension while Adobe really wants a .tif extension. I can tell PS to not use any extension, but then I have to remember to add the .tiff manually, and that is a pain and I always forget. Not an option.
    So, what I do is import the DNG, set the white balance in Aperture and then run the Dfine (hope I spelled that right) plug-in which saves out as a TIFF. Then I open in Photoshop and do the lens correction (which does not work quite as well with the available lens profile as Camera Raw does) and do whatever else is needed in Photoshop.
    But, aside from not being able to use Camera RAW it's really the little things that make me crazy. Always having to remember to do a CMD\ to set the most recently edited version as the pick is something I need to do, but forget at least half the time. Also having to close the stack every time. I have too much to do, and I ought to have an option to do that automagically IMHO. Those little details help prevent screw ups and keep me focused on images instead of filing. I am a very poor file clerk. That's what software is for.

  • Keywords cannot be assigned to multiple images

    A keyword can NOT be assigned to multiple images at the same time when following the procedures outlined in the Aperture help. I can't find this problem addressed in a FAQ or knowledge base. We're told to select multiple images in the Browser window then drag a keyword to any of the images to assign that keyword to all the selected images. This does not work -- only the specific image on which the keyword is dropped will actually be tagged with the keyword. The other images, though properly selected, do not receive the keyword. The keyword must be assigned to one image at a time. Needless to say, this is more time consuming than it's worth when you're faced with thousands of images that need to be tagged.
    I own two registered copies of Aperture, both up to date with the latest patches, and the problem occurs on both systems, so I know its not something related to a single computer.
    Surely I'm not the only person who has encountered this problem?

    I thought I had the same problem, but then did the following:
    1. In Browser (grid view) went ot lower right and turned off the "primary only button" (ie it should not be "lit")
    2. Highlighted the images I wanted to apply the same keyword to
    3. Opened the keyword HUD
    4. Clicked on the keyword I wanted and then dragged it to one of the highlighted images in the browser

Maybe you are looking for

  • User Exit or BADI for Batch determination in VL01N

    Hi Folks,             While creating deliveries in VL01N, SAP determines the available batch numbers for the material. Determining batch number will happen based on the characteristic values configured. My requirement is that i need to have access of

  • LDAP connection problem

    I'm trying to connect to a server using Ldap in Java, but the connection dosent work. I did try to connect to my computer just for a test, my machine is on a network that use the server. Is it possible to connect to it using Ldap like this : env.put(

  • PURCHASE REQ,No data satisfying selection criteria exists(error msg:MEQ009)

    Hi, I am unable to view My Purchase requisition history in ME51N Error message "No data satisfying selection criteria exists" is displayed in the selecton variant message number: MEQ009 pls. help me Regards

  • Server cannot connect to cluster

    Hi I have been scratching my head about this problem for a while. I have three servers all using the same coherence-cache-config file - one runs inside weblogic, one is the coherence.sh monitoring application and the third is an invocation of the Def

  • User access Autherization

    Hi, is it possible to create user access authorization for the particular storage location. E.g. plant 1000 has 1001 and 1002 storage locations and user A have to be given the authorization only for location 1001. if this is possible pls explain me h