Move an image when mouseDragged event occurs

I have a JFrame with an image in it.Now when the user press and hold the mouse button(that is when the mouseDragged event occurs)on the image anywhere I want to make the image as movable.
how should I do that , i am not getting any ideas.This is important , please let me know how to do that.
Sample code will be very helpful.
Thank you

Are you displaying the image in Applet....
You can use something like this...
void panel_mouseDragged(MouseEvent e) {
Container c = this.getParent();
if (c instanceof JViewport) {
JViewport jv = (JViewport) c;
Point p = jv.getViewPosition();
int newX = p.x - (e.getX()- m_XDifference);
int newY = p.y - (e.getY()- m_YDifference);
int maxX = this.getWidth() - jv.getWidth();
int maxY = this.getHeight() - jv.getHeight();
if (newX < 0)
newX = 0;
if (newX > maxX)
newX = maxX;
if (newY < 0)
newY = 0;
if (newY > maxY)
newY = maxY;
jv.setViewPosition(new Point(newX, newY));
void panel_mousePressed(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
m_XDifference = e.getX();
m_YDifference = e.getY();
void panel_mouseReleased(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}

Similar Messages

  • When both plug-in objects and jQuery mouse events are present, Firefox re-starts the plug-in object (eg Flash movie) after a jQuery mouse event occurs. This doesn't happen in any other browser. How can I get around this?

    Please check http://www.syus.com for an example. There is a Flash movie underneath the main navigation. The main navigation has a jQuery mouse event, and when you mouse over a button in the main navigation, the Flash movie re-starts. I can confirm that this happens not only on Flash swf files, but on standard <object> YouTube embeds.

    Ok, I promise this is my last post without your help. I did some more troubleshooting and it only seems to happen when jQuery appends elements to the body that were previously invisible. In other words, I can simply change the css in jQuery from using element.css('display','inline'), but if I try to use something like slideDown or other jQuery tooltip functions that append and/or remove elements or style definitions it causes the "object restart" bug.
    It is impossible for any developer to eliminate this bug without changing the actual source of jQuery, which I can't do. My only other option is not to use sophisticated show/hide jQuery elements like drop-down menus and tooltips on the same page as an embedded object, but I don't want to do this since Safari, Chrome and even IE (dear God) users won't have a problem with this. I think this is a major major bug that should be fixed in Firefox 4 as more and more sites will be looking to use the latest jQuery plugins.

  • Bug? - PSP LED Moves on FP when Binding Change Occurs

    [LabVIEW 2010]
    When I update the binding on the control the PSP LED moves. This is annoying
    Cheers
    -JG
    Unable to display content. Adobe Flash is required.
    Certified LabVIEW Architect * LabVIEW Champion

    This was reported to R&D (CAR ID # 296216) for further investigation. I did try saving the VI before the variable to which the control was bound was changed, but the same behavior occurred.
    Thanks for the feedback!
    -Sean N
    Applications Engineering Specialist - Semiconductor Test
    National Instruments

  • How to call the custom  code in Seeded OA pages when an event Occured.

    Hi,
    I need to call a Oracle Create Task API when User saves the data from Seeded OA Page(Sales OA Page).When User Pressed on the Save button,based on Value he selected in " Sales Methodology" Field ,I need to call Call API.
    How can I achieve it.Is it suggestable to call Custom Code in OA Page.
    Thanks
    Raju.

    hi
    extend the controller
    1.) In PFR method of controller capture the event of save button.
    2.) If the save button event ocurred capture the value of Sales Methodology.
    3.) if select Sales Methodology is required value then call the API using the below method (change it accordingly)
    import java.sql.CallableStatement;
    import java.sql.SQLException;
    import java.sql.Types;
    OADBTransaction txn = getDBTransaction();
    CallableStatement cs =
    txn.createCallableStatement("begin dbms_application_info.set_module(:1, :2);
    end;");
    try
    cs.setString(1, module);
    cs.setString(2, action);
    cs.execute();
    cs.close();
    catch (SQLException sqle)
    try { cs.close } catch (Exception(e) {}
    throw OAException.wrapperException(sqle);
    thanx
    Pratap

  • How to Stop the timer in the TimedTrigger UI element when an event occurs

    Hi all
    I have a webdynpro View where i have many UI elements(which supports an event)  along with TimedTrigger UI element.
    Now my requirement , i want to check at single line if any event happens in the View then i want to stop the timer in the TimedTrigger UI element.
    can you please provide any peace of code related to this??
    Thanks
    Bindu

    Hi Bindu,
    From help.sap.com:
    http://help.sap.com/saphelp_nw70/helpdata/EN/03/7c6b40dde0980ae10000000a155106/frameset.htm
    To prevent events being triggered by UI element TimedTrigger, proceed as follows:
    1. Disable the action that is bound to the UI elementu2019s onAction property.
    Can be done as:
    wdThis.wdGet<Your_TimedTrigger_action>Action().setEnabled(false);
    2. Set the value of the delay to 0 seconds
    As suggested in previous post to this thread.
    3. Disable UI element TimedTrigger
    Create a boolean type of context attribute and bind it to the "enabled" property of the Timed Trigger. Set its value to false to disable the timed trigger.
    Regards,
    Alka.

  • Refreshing OutputText component on main page when region event occurs

    Greetings,
    I am attempting to force a refresh on an output text component whose value is retrieved from a session scope bean property. The bean property is being updated by a methodAction call within one of the sub-task flow regions. I have tried accomplishing this by attempting to force a ppr event via
    AdfFacesContext context = AdfFacesContext.getCurrentInstance();
    context.addPartialTarget(component);using an object bound to component on the page after the update is made. I started to look into contextual events but all of the examples refer to explicit regions defined in the pagedef. This is not the case using UI Shell.
    Any suggestions on how to refresh this 'parent-level' component?
    Thanks!
    michael
    Edited by: michael faith on Mar 3, 2010 11:25 AM

    Hi,
    I am facing similar problem.
    I am able to refresh a region based on another region but not a component in parent page based on a region.
    I am using contextual event framework.
    Can we point a region as a partial trigger for a component on the main page?
    Did u get the solution to your problem?
    Any help would be highly appreciated.
    Thanks.

  • Having iCal peep when event occurs... way too long of a process

    When i set appointments in ical with reminder, in order to get a peep when the event occurs, i need to set reminder->message->on date and then iCal sets the reminder 15 minutes before the date! I then need to fix this. This process is really annoying. How can i make iCal set off a reminder peep without going through this process. I would be happy to just get rid of the fixing the 15 minutes thing again and again.

    What is the exact CODEC in the MOV files?
    Also, Exporting to H/264 can be CODEC dependent. Which H.264 CODEC is installed and chosen?
    Good luck,
    Hunt

  • How can I save the images and movies on a  external Disk from iphoto program, to protect the images when problems occur in the laptop,

    How can I save the images and movies on a  external Disk from iphoto program, to protect the images when problems occur in the laptop,

    Most Simple Back Up:
    Drag the iPhoto Library from your Pictures Folder to another Disk. This will make a copy on that disk.
    Slightly more complex: Use an app that will do incremental back ups. This is a very good way to work. The first time you run the back up the app will make a complete copy of the Library. Thereafter it will update the back up with the changes you have made. That makes subsequent back ups much faster. Many of these apps also have scheduling capabilities: So set it up and it will do the back up automatically.
    Example of such apps: Chronosync - but there are many others. Search on MacUpdate or the App Store
    If you want to back up the Photos only:
    Export them using the File -> Export command.
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.

  • How to view the image by using mousedrag event?

    How can i move the full image by using mousedrag event(not using scrollBar and the frame should not reziable).
    e.g
    click the mouse in image and drag right side or towards down,the image should move to till the end in width or height
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class LoadAndShow extends JPanel implements MouseMotionListener{
        BufferedImage image;
        Dimension size = new Dimension();
        public LoadAndShow(BufferedImage image) {
            this.image = image;
            size.setSize(image.getWidth(), image.getHeight());
         * Drawing an image can allow for more
         * flexibility in processing/editing.
        protected void paintComponent(Graphics g) {
            // Center image in this component.
            int x = (getWidth() - size.width)/2;
            int y = (getHeight() - size.height)/2;
            g.drawImage(image, x, y, this);
        public Dimension getPreferredSize() { return size; }
        public static void main(String[] args) throws IOException {
             //set the image path
            String path = "Images/dinette.jpg";
            BufferedImage image = ImageIO.read(new File(path));
            LoadAndShow test = new LoadAndShow(image);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setResizable(false);
            f.add(test);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
            //showIcon(image);
         * Easy way to show an image: load it into a JLabel
         * and add the label to a container in your gui.
        private static void showIcon(BufferedImage image) {
            ImageIcon icon = new ImageIcon(image);
         public void mouseDragged(MouseEvent arg0)
              // TODO drag the image
         public void mouseMoved(MouseEvent arg0)
    }

    Following is the updated code for image move on mouse move.
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.awt.event.MouseListener; public class LoadAndShow extends JPanel implements MouseMotionListener,MouseListener{
    BufferedImage image;
    Dimension size = new Dimension();
    Point pt;//Maintain the Current Pressed Values of Mouse
    Rectangle rect;//Maintain the moving position of Mouse     public LoadAndShow(BufferedImage image)     {
    this.image = image;
    size.setSize(image.getWidth(), image.getHeight());
    this.addMouseListener(this);
    this.addMouseMotionListener(this);
    * Drawing an image can allow for more
    * flexibility in processing/editing.
    protected void paintComponent(Graphics g) {
    // Center image in this component.
    int x = (getWidth() - size.width)/2;
    int y = (getHeight() - size.height)/2;
    g.drawImage(image, x, y, this);
    }     public Dimension getPreferredSize() { return size; }     public static void main(String[] args) throws IOException {
    //set the image path
    String path = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg";
    BufferedImage image = ImageIO.read(new File(path));
    LoadAndShow test = new LoadAndShow(image);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setResizable(false);
    f.add(test);
    f.setSize(400,400);
    f.setLocation(200,200);
    f.setVisible(true);
    //showIcon(image);
    * Easy way to show an image: load it into a JLabel
    * and add the label to a container in your gui.
    private static void showIcon(BufferedImage image) {
    ImageIcon icon = new ImageIcon(image);
    }     public void mouseClicked(MouseEvent e) {
    }     public void mousePressed(MouseEvent e) {
    pt = e.getPoint();
    rect = this.getBounds();
    }     public void mouseReleased(MouseEvent e) {
    }     public void mouseEntered(MouseEvent e) {
    }     public void mouseExited(MouseEvent e) {
    }     public void mouseDragged(MouseEvent e) {
    Point p=e.getPoint();
    moveImageOnMouseMove(p);
    }     public void mouseMoved(MouseEvent e) {
    * This Function is used for calculate the Dragging point of Mouse and set the image on particular points
    * @param p Point hold the dragging point of Mouse
    private void moveImageOnMouseMove(Point p)
    int xDelta = p.x - pt.x;
    int yDelta = p.y - pt.y;
    rect.x = rect.x + xDelta;
    rect.y = rect.y + yDelta;
    this.setLocation(rect.x, rect.y);
    this.repaint();
    }}   If you have any query related with the code please let me know.
    Manish L
    MS Technology
    www.ms-technology.com
    Edited by: mannymst on Sep 18, 2008 5:53 AM
    Edited by: mannymst on Sep 18, 2008 6:05 AM

  • MouseDragged Event donot Happen when startDrag method is called

    Hi
    I am developing a component (JLabel), which is DragSourceListener and MouseMotionListener at the same time.
    When DragGestureRecognize starts drag ,mouseDragged event don't happend
    Seems a Bug

    No thoughts from anyone on this? Seems to me, this means that true full-app window drag images aren't realistically possible with Swing when the OS doesn't natively support it, even if you want to try to code it yourself.
    It is an absolute must to always be notified of the mouse position so you'll know where to draw the ghosted drag image. The only way I can think of is to glass pane your whole JFrame but that won't work because then you lose the response of all your drop targets.
    Please take a second to share if you know of any listener at all that can be added so that an event is fired wherever the mouse is dragged within the JFrame- regardless of what component it is dragged over. Anything short of the glass pane approach since we can't have the glass pane catching all the events or the whole DnD system is foobar'ed.

  • PC/64/Windows 7/XIStandard recently installed/unable to put footer into document because I can't move to the bottom of the image when in footer application mode.  Display is at recommended 1920x1080.  Is there a solution or is it a flaw in the program?

    PC/64/Windows 7/XIStandard recently installed/unable to put footer into document because I can't move to the bottom of the image when in footer application mode.  Display is at recommended 1920x1080.  Is there a solution or is it a flaw in the program?

    Don't have a direct answer. But did you install the updates. They might resolve the problem.

  • How can I improve quality of image when burning a movie to a DVD

    How can I improve quality of image when burning a movie to a DVD?

    What resolution are you using?  If the DVD is to be playable on an ordinary DVD player, only ordinary TV resolution is supported.  You need Blue ray for HD.
    Geoff.

  • Using Lightroom 5.5 and Photoshop CC2014. Images no longer open in Photoshop when using "edit in" command. Photoshop opens but no image when trying to move between LR and PS. Any suggestions?

    Using Lightroom 5.5 and Photoshop CC2014. Images no longer open in Photoshop when using "edit in" command. Photoshop opens but no image when trying to move between LR and PS. Any suggestions?

    1. You have allowed Apple to auto-upgrade your Mac
    Turn off auto-update here:
    Menu > Apple > System Preferences > App Store
    2. The Icons on your dock are Aliases not real apps
    They point to where the apps really are which is:
    For Pages 5.2.2 in your Applications folder
    For Pages '09 in your Applications/iWork folder
    3. You are alternately opening documents randomly with either version of Pages
    Both Pages have the same file extension .pages and there is no certainty as to which version opens them when you double click on a file.
    right click on the file and choose which version you want to open it
    4. Pages '09 can not open Pages 5 files
    Pages 5 can not open Pages '08 files, and will convert and change Pages '09 and Word files.
    It will also auto save opened files into its own format.
    You can export these back to Pages '09 if you need to:
    Menu > File > Export > Pages '09
    5. Yes Pages 5.2.2 is a marked downgrade
    Pages 5.2.2 has a few improvements but has had over 110 features removed and is buggy.
    Sooner or later you will not be able to open a file or have it damaged in some way and it has a complex obscure file format largely incompatible with everything else, so you will not be able to rescue the contents of your file. If Pages or some third party server/eMail don't trash your file, eventually Apple will do it for you as it did when it released Pages 5 last September. I recommend using Pages '09 for the time being whilst you look for viable alternatives, some are here already and some are on the way.
    For further information about what has happened:
    http://www.freeforum101.com/iworktipsntrick/viewforum.php?f=22&sid=0882463378700 abf43a0f2433506bbbc&mforum=iworktipsntrick
    Peter

  • Error 43 when trying to export movie to image sequence

    Hello, I'm trying to export a movie to image sequence. I did this successfully on our other xp machine but am getting an error 43 message with this one. I have searched online and on the forums and can't find a solution. Help would be appreciated.
    Thanks,
    Sharon

    Jenny, the solution for me was to save to the desktop. I can export when I save there.
    Sharon

  • Power Shell script to send a email with event details when an specified event occur

    I want a power shell scrip to send a email to a specific email id with the event details when an specified event triggered. The default option to trigger the email on event occur is failed.

    Why is everybody now saying "I want, I want, I want"
    Can you say what is happening?  Can you post a script with a line that is failing?  No!  All you want is a free script.
    Start by learning how to script.   Try at least to write a simple "hello World" script.  Until then you cannot post here.
    ¯\_(ツ)_/¯

Maybe you are looking for