Dragging a JPopupMenu around with a mouse. What am I doing wrong?

Hello,
I need to move a JPopupMenu around with a mouse, but it isn' working out as expected.
Menu is being moved erraticaly, jumping here and there a bit, and lagging behind the mouse movements.
Although it is moving in general direction of mouse drags.
Anyone has an idea what am I doing wrong?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JPopupMenuDragTest {
    public static void main(String[] args) {
        new JPopupMenuDragTest();
    JPanel contents = new JPanel();
    DraggablePopupMenu popup = new DraggablePopupMenu();
    public JPopupMenuDragTest() {
        contents.setPreferredSize(new Dimension(512, 384));
        contents.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                popup.show(contents, e.getX(), e.getY());
        showFrame(contents);
    void showFrame(JPanel contents) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(contents);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    class DraggablePopupMenu extends JPopupMenu implements MouseListener, MouseMotionListener {
        JButton btnDragger = new JButton("drag me");
        int clickx, clicky, menux, menuy;
        public DraggablePopupMenu() {
            add(btnDragger);
            btnDragger.addMouseListener(this);
            btnDragger.addMouseMotionListener(this);
        public void mousePressed(MouseEvent e) {
            clickx = e.getX();
            clicky = e.getY();
            Point locationOnScreen = getLocationOnScreen();
            menux = locationOnScreen.x;
            menuy = locationOnScreen.y;
        public void mouseDragged(MouseEvent e) {
            int xOffset = e.getX() - clickx;
            int yOffset = e.getY() - clicky;
            setLocation(menux + xOffset, menuy + yOffset);
        public void mouseClicked(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {}
        public void mouseExited(MouseEvent e) {}
        public void mouseMoved(MouseEvent e) {}
}

Thanks, that kind of works. The point is, I have to use Java 1.5, which does not support getX/YOnScreen for MouseEvents.
I changed the code to:
        public void mouseDragged(MouseEvent e) {
            Point p = e.getPoint();
            SwingUtilities.convertPointToScreen(p, (Component) e.getSource());
            setLocation(p.x - clickx, p.y - clicky);And everything seems fine, until iI drag the popup out of the containing JFrame.
Then the disco starts.
If you can find the answer for this, tat would be great, but thanks anyway.

Similar Messages

  • Message "this app is not compatible with this iPad" What am I doing wrong?

    I am trying to update my apps and when I touch update all I get the message 'this app is ot compatible with this I-pad.  this has never happened before, what am I doing wrong?

    One or more of the apps you are updating is seeing that you have not yet gone to ios5.  All the iwork app changes, for example, will not upgrade until you do.   What you can do is tick them individually.  If that particular app will update, then it will.  If it won't it will tell you, and you can go back and get them later after you do the ious 5 update.  Last night i decided to update before i started the ios 5 upgrade, and there were 16 apps waiting for up date.  All but 5 did update, but not the i works, and 2 others.
    It takes a little longer to do them 1 at a time, but it is better than staring at the stupid 'not eligable' notice.

  • Attempting to test Function with Bind Variable --- What am I doing wrong?

    When I try to test a function (ComputeFreight) with a bind variable, I get an error, returned.....
    "SQL> EXEC :ComputeFreight :=V_ComputeFreight;
    BEGIN :ComputeFreight :=V_ComputeFreight; END;
    ERROR at line 1:
    ORA-06550: line 1, column 25:
    PLS-00201: identifier 'V_COMPUTEFREIGHT' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored"
    What am I doing wrong?
    Below is my code with description ----
    create or replace function "ComputeFreight"(p_ORDERNUMBER IN C_ORDER.ORDERNUMBER%TYPE) -- Passing Ordernumber into Function
    return NUMBER
    is
    -- Declaring Variables
    v_ComputeFreight NUMBER(10,2);
    v_low number (10,2) := 0.05;
    v_high number (10,2) := 0.07;
    v_SUBTOTAL NUMBER(10,2);
    begin
    -- Computing order subtotal (Retrieving Item cost and qty from two different tables, multiplying and adding total order cost)
    SELECT SUM(O.QUANTITY * I.ITEMPRICE) INTO v_subtotal
    FROM ORDER_LINE O JOIN INV_ITEM I
         ON (O.ITEMNUMBER = I.ITEMNUMBER)
    WHERE O.ORDERNUMBER = P_ORDERNUMBER;
    -- Testing to see which freight charge rate to use
    IF
    v_subtotal < 300.00 THEN
    v_computefreight := v_subtotal * v_low;
    ELSE
    v_computefreight := v_subtotal * v_high;
    END IF;
    -- Returning Freight Charge
    RETURN v_ComputeFreight;
    end "ComputeFreight";
    -----------------------------------

    You have made at least 2 errors.
    The first one is the name of your function:
    create or replace function "ComputeFreight" (You use double quotas and the mixed case in the function name - it means you
    make your function name case-sensitive. In the call of your function you have to use double-quoted form "ComputeFreight", nothing else.
    If you your function name has to be case-insensitive, don't use double quotas or
    use upper-case form: "COMPUTEFREIGHT".
    The next mistake is how your call you function. You have to do the following:
    var V_ComputeFreight number
    EXEC :V_ComputeFreight := <your function name>
    V_ComputeFreight is a bind variable and you have to read more about this.
    Rgds.
    P.S. and as Dave fairly remarked above you have to pass the argument into the function.
    Message was edited by:
    dnikiforov

  • HT204053 Trying to set up my apple TV and it doesn't want to accept the Apple ID and password I have just set up with iTunes.  What am I doing wrong?

    I am having trouble signing into my apple ID acct on my new device Apple TV.  It doesn't seem to accept my newly created  Apple ID and password.  What am I doing wrong?  Is there a delay in creating the acct to when I can use it?

    yeah have reguested apple id and reset password still nothing

  • Photos from Win XP will not Sync with 3G iphone what am I doing wrong

    Need some help, just got the iphone and the only thing I can't understand is how to transfer my photos from my PC to the phone. I understand I use Itunes and point it to the folder/photo I want to sync. Itunes goes through it optimizing 1 of 29 photos (only doing 29 photos to start) but then when I go to the phone I have the normal Camera Roll Album and one folder listed. In the folder listed is only one photo which is all messed up.
    I understand the phone takes photos and displays photos at one res, and I thought Itunes doesn't care what res the photo from the PC is cause it optimizes it to be viewed on the phone.
    What am I missing ? and what is this folder that keeps being built ipod photo cache. Any help would be wonderful and yes I did read the "Iphone User Guide" that came with the phone.

    Not sure what the issue is that you are having. Sounds like you are doing the right thing.
    You point iTunes to a folder that contains pictures (or more subfolders that contain pictues...1 subfolder deep). Then tell it to sync. iTunes does its "optimize" thing. Then they sync over. Each subfolder in that folder you pointed to becomes a library.
    eg:
    C:\PHOTOS you point it to.
    C:\PHOTOS\FAMILY
    C:\PHOTOS\WORK
    C:\PHOTOS\FRIENDS
    C:\PHOTOS\WALLPAPER
    C:\PHOTOS\MISC
    are all under it.
    Each of those becomes a library on the iPHone (Family, Work, friends, etc)
    Photos from those folders go to phone (and photos from the root you pointed it to).
    The extra folder it makes (think it tries to mark it hidden unless you have it set to show hidden files) is just stuff for iTunes to keep track (like HASH data and other stuff) to know what it has synced so it can tell what is new and what is old if you add more photos or folders later.
    I have some huge images on my PC that I sync over without issue. iTunes scales them down when syncing to the phone (the whole optimize stuff).
    Message was edited by: DaVBMan

  • Cannot set up Mail with GoDaddy Account, what am I doing wrong?I

    I searched the correct way to do this through GoDaddy, my hosting service and got these directions, which I have tried, but didn't work.
    *To Set Up Apple Mail for SMTP Relay
    1. From the Mail menu, click Preferences.
    2. In the Preferences window, click Accounts.
    3. In the Account window, click Account Information.
    4. From the Account Type list, select POP.
    5. In the Description field, type a name for the account.
    6. In the Email Address field, type your email address.
    7. In the Your Name field, type your full name.
    8. In the Incoming Mail Server field, type pop.secureserver.net.
    9. In the User Name field, type your user name (your full email address).
    10. In the Password field, type the password to your email account.
    11. In the Outgoing Mail Server (SMTP) field, type smtpout.secureserver.net.
    12. In the SMTP Server Options window, in the Outgoing Mail Server field, type smtpout.secureserver.net.
    13. In the Authentication field, type your password.
    14. In the Server Port field, type 80 or 3535.
    15. In the User Name field, type your SMTP user name.
    16. In the Password field, type your SMTP password.
    17. Click OK.
    Obviously, I'm connected to the internet...
    I tried doing this through POP and IMAP, there is an error message saying unable to connect. What can be done to make this work?

    the 3535 is not gonna work...the 110 will work...I have been dealing w/ godaddy.com .mac and mac support for 5 months with compatibility. It is the worst.. mac says they never heard of godaddy and godaddy had me run a trace route so then I had to deal w/ my isp for no good reason since other browsers could reach godaddy so it is not my stream.. It is the worst. These are suposed to be the easiest and most seemless systems and they cannot sync. I use firefox to get to go daddy on my macbook and it is as if I am using dial up. I am ready to just cancel .mac which is really another headache to learn..and godaddy and just move everything over to a company that can handle everything. My web business has been on hold since January. It makes no sense. I got the mac so I would not have to deal w/ the windows registry error answer.. now godaddy tells me they are built for windows.
    There is no winning at this. I have spent countless hours on phone support after spending countless hours researching the answers only for all support lines to tell me i can "go to...website for more info..." it is as bad as using windows.
    Very dissatissfied,
    p

  • Replacement Ipod Dead With Same Problems, what am i doing wrong?

    I bought a Classic, it started to not play some of my songs, then it crashed, then i couldnt revive it or put anything on it, so i sent it back and received a new one promptly. Guess what, same problems, stopped playing some songs about a week ago, HDD makes strange sounds as if trying and failing to locate tracks, then i did a restore after i reworked my itunes library and now the pc is starting to not recognize it and cant add songs and restoring is a pointless option, ipod is full of songs up to the letter G after a failed library sync. PlEASE help me remedy so that i dont have to replace my replacement with another ipod that needs to be replaced

    Ok here's what I did:  While the modem was still connected to my PC, my router was plugged in and just had power so I did the hard reset like you said.  Then I plugged the modem into the router, reset my modem and plugged the ethernet cable back into my tower and Now it works.  The only problem is that I have is that when i get to http://198.162.1.1/ and leave username blank and password admin, I keep getting 401 Unauthorized.  I would really like to be on a secured network but I never could because the easylink advisor wouldn't work right and I couldn't get the laptop to get connected.  Thank you for your help.

  • Help with a script (what am I doing wrong)

    tell application "Finder"
    set theFolder to (choose folder with prompt "choose the user folder") as Unicode text
    set newFolder to make new folder at theFolder as Unicode text with properties {name:"test folder"}
    set targetFolder to newFolder
    move entire contents of (theFolder & "Library:Preferences") to targetFolder
    end tell
    error "Can’t get entire contents of \"Macintosh HD:Users:username:Library:Preferences\"." number -1728 from «class ects» of "Macintosh HD:Users:username:Library:Preferences"
    also I would like the new folder in Library not user folder

    I had some time to give the connected volume stuff another look, so I tweaked the script a little. This latest version will handle getting the users from local or connected volumes as well as connected accounts. I threw in some labels in the choice dialog so you can see what the volumes are, and changed the time stamp a little to avoid using either the POSIX or Finder path delimiters.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    -- remove user preferences to a backup folder
    set theUsers to {}
    repeat with aDisk in (get list disks)
    set aDisk to contents of aDisk
    tell application "System Events"
    if (local volume of disk aDisk) then -- get users from local disks
    if (startup of disk aDisk) then
    set label to "[Startup Volume] "
    else
    set label to "[Local Volume] "
    end if
    repeat with aUser in paragraphs of (do shell script "ls '/Volumes/" & aDisk & "/Users'")
    if aUser is not in {"Shared"} then set the end of theUsers to (label & aDisk & "/Users/" & aUser)
    end repeat
    end if
    try
    if (server of disk aDisk is not missing value) then -- get users from connected disks
    try
    repeat with aUser in paragraphs of (do shell script "ls '/Volumes/" & aDisk & "/Users'")
    if aUser is not in {"Shared"} then set the end of theUsers to ("[Server Volume] " & aDisk & "/Users/" & aUser)
    end repeat
    on error errmess -- get connected user
    log errmess
    set the end of theUsers to ("[Server " & (server of disk aDisk) & "] " & aDisk)
    end try
    end if
    end try
    end tell
    end repeat
    set theChoice to (choose from list theUsers with title "Move preferences to backup" with prompt "Select an account to move user preferences:" with empty selection allowed) as text
    if the result is in {"false", ""} then return -- no selection
    set theChoice to "/Volumes/" & text ((offset of "] " in theChoice) + 2) thru -1 of theChoice -- strip off the volume labels
    set theSource to (theChoice & "/Library/Preferences") as POSIX file as text as alias
    set theDestination to (theChoice & "/Library") as POSIX file as text as alias
    tell ((current date) as «class isot» as string) to set timeStamp to (text 6 thru 7) & "-" & (text 9 thru 10) & "-" & (text 3 thru 4) & space & (text 12 thru 13) & (text 15 thru 16) -- ISO time = yyyy-MM-ddThh:mm:ss
    set theName to "Preferences copy " & timeStamp
    try
    set targetFolder to ((theDestination as text) & theName) as alias
    on error errmess
    log errmess
    tell application "Finder" to make new folder at theDestination with properties {name:theName}
    set targetFolder to the result as alias
    end try
    tell application "Finder" to move items of theSource to targetFolder
    </pre>

  • Some websites do not display properly. I am getting overlapping of menu's. This does not happen with IE. What am I doing wrong?

    I log on to the same wesite on Mozilla and IE. On mozilla the left hand menu overlaps one over the other but the same does not occur with IE, I ask this as I prefer mozilla. Do I need to change any configuration setting. I have a Dell Studio Laptop which is only about 5 months old. Unfortunately I cant post the url because it needs a password to get into the site.

    Reset the page zoom on pages that cause problems: <b>View > Zoom > Reset</b> (Ctrl+0 (zero); Cmd+0 on Mac)<br />
    See http://kb.mozillazine.org/Zoom_text_of_web_pages
    If you increased the minimum font size then try the default setting 'none' as a high value can cause issues like you described.
    * Tools > Options > Content : Fonts & Colors > Advanced > Minimum Font Size (none)
    * Tools > Options > Content : Fonts & Colors > Advanced > [X] "Allow pages to choose their own fonts, instead of my selections above"
    See also [[Websites look wrong]

  • HT1414 My generation 1 iPad won't update even when I try manually with iTunes.  What am I doing wrong?

    So I have tried updating in settings and iTunes and nothing any suggestions?

    If you have the 1st gen iPad you cannot update via the settings unless you have iOS 5 on it and that is as high as you can go anyway - actually 5.1.1 is the limit.

  • Trouble with  vst pluggin, what  am i doing wrong??

    trying to place vst plugs , i added to the folder , but nothing??? anyone can set me in right direaction , im clearly doing something wrong

    ...additionally...
    Many VSTs are available as AUs.
    Another tip:wrappers exist. Wrappers allow most of your VSTs to load as AUs-use AUs if they are available.
    Find a wrapper here:
    http://www.fxpansion.com/product-auadapter-main.php

  • I am trying to download firefox to my android and get this meesage" there are no android phones associated with this account " what am I doing wrong?

    I would like to sync my laptop and android but get the above message

    To install Firefox from the Android Market web site, you must be logged in to the web site and your phone using the same Google account. If that doesn't work, you can follow the instructions here for other ways to install Firefox for Android: https://wiki.mozilla.org/Mobile/Platforms/Android

  • HT1751 i could not get the file to drag over using windows 7  what am i doing wrong?

    I am trying to back up itunes on an external hard drive.  When I get to the advanced tab (in edit_preferences) I see the file but I am unable to drag it to the external drive.  what am i doing wrong?

    You cannot drag anything from the Advanced tab.
    Go to the location indicated in the Advance tab, that folder is what needs to be moved.

  • Using my apple ID and password on Mobile Me, I get the message  "Verification Failed"  .  Could not communicate with the server.  What am I doing wrong?

    Using my Apple ID and password on Mobile Me, I get the message "Verification Failed".  Could not communicate with the server"  What am I doing wrong?

    There is a MobileMe forum.  You might have better luck their.

  • I have a frisky mouse that came with my iMac. I barely touch it and the screen I'm on is swiped away. What am I doing wrong?

    I have a frisky mouse that came with my iMac. I barely touch it and the screen I'm on is swiped away. What am I doing wrong?

    Hi lindseyclarissa,
    Welcome to the Apple Support Communities!
    Please read over and use the attached article as a reference on how to adjust the mouse tracking and scrolling speeds.
    Apple Wireless Mouse: How to Adjust Tension, Tracking, and Double-Click Speed
    http://support.apple.com/kb/HT3080
    3. Adjust the tracking speed or double-click speed to a level that's comfortable for you.
    Have a great day,
    Joe

Maybe you are looking for

  • Change mode of the excise invoice is showing zero excise values

    H ifriends, The change mode of the excise invoice is showing zero excise values.....and the same is reflected in the ARE1 While creating the excise invoice,its showing BEd/Ed and Shed and after saving,if i check the doc the values are shown aero... T

  • Need advise : Risks of using  materialized views

    Hi - I need some advise on whether using a materilzied view can help in teh folloiwng scenario. Scenario : You have a large tables which has sy 60 million rows, This is a demand management application which accesses this data at various aggregate lev

  • 4/3 matrix shape in calandar in jsp

    i created the jsp page to view the calander, but i am getting output as the 12 months coming vertically i need it to b cum in 3/4 or 4/3 matrix shape here is my code <%@page import="java.util.*,java.text.*" %> <html> <head> <title>Print a month page.

  • Af:menu Problem in jdev 11.1.1.6 with IE 9

    I've oracle ADF fusion web application using jdev version 11.1.1.6 the template there is af:menu that contains many of af:commandmenuItem When I use IE9 I can't scroll down to click on commandMenuItem as the menu keep scrolling then returns to the fi

  • Hi can the battery of ipod nano 2nd genration be replaced ? if yes where can i fix it in riyadh/saudi arabia

    h it is my pleasure to own 3 product from apple. the only problem i have is with the battery of my ipod nano 4 GB battery that is not working without the charger. i would like to know if it can be replaced? if yes can i know where can i go in saudi a