Not detecting mouse exit events

I'm developing a Java application that implements an 'auto-hide' functionality - similar to that of the Office Shortcut bar - such that when the mouse moves outside of the application frame the window auto-hides. I'm using the Mouse Exit event to detect when the mouse moves outside of the the application frame and then I 'hide' the window (or rather resize it to 2 pixels high) so I can then detect the Mouse Entered event to restore the window.
This works OK but occasionally if I move the mouse quick enough the exited event isn't detected and the window doesn't always hide.
Are there any other ways of detecting if the mouse moves outside of the application frame (so I can also trigger my 'hide' function) without relying on other events such as windowLostFocus.
Thanks,
Richard.

I have one suggestion:
Check that the component that you use to monitor mouse exit and enter events has at least one pixel visible from all sides (most layout managers allow a border (not a Border class or subclass) that is not occupied by child subcomponent).
For example if you will place some other component in container directly so some side then mouse enter and exit events will be fired on that component and not on the container.

Similar Messages

  • Mouse Drag in JDialog produces Mouse Enter & Mouse Exit events in JFrame.

    Hi, all.
    Do I have a misconception here? When I drag the mouse in a modal JDialog, mouseEntered and mouseExited events are being delivered to JComponents in the parent JFrame that currently happens to be beneath that JDialog. I would not have expected any events to be delivered to any component not in the modal JDialog while that JDialog is displayed.
    I submitted this as a bug many months ago, and have heard nothing back from Sun, nor can I find anything similar to this in BugTraq.
    Here is sample code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    * This class demonstrates what I believe are TWO bugs in Mouse Event handling in Swing
    * 1.1.3_1, 1.1.3_2, 1.1.3_3, and 1.4.0.
    * 1) When a MODAL JDialog is being displayed, and the cursor is DRAGGED from the JDialog
    *    into and across the parent JFrame, Mouse Enter and Mouse Exit events are given to
    *    the parent JFrame and/or it's child components.  It is my belief that NO such events
    *    should be delivered, that modal dialogs should prevent ANY user interaction with any
    *    component NOT in the JDialog.  Am I crazy?
    *    You can reproduce this simply by running the main() method, then dragging the cursor
    *    from the JDialog into and across the JFrame.
    * 2) When a MODAL JDialog is being displayed, and the cursor is DRAGGED across the JDialog,
    *    Mouse Enter and Mouse Exit events are given to the parent JFrame and/or it's child
    *    components.  This is in addition to the problem described above.
    *    You can reproduce this by dismissing the initial JDialog displayed when the main()
    *    method starts up, clicking on the "Perform Action" button in the JFrame, then dragging
    *    the cursor around the displayed JDialog.
    * The Mouse Enter and Mouse Exit events are reported via System.err.
    public class DragTest
        extends JFrame
        public static void main(final String[] p_args)
            new DragTest();
        public DragTest()
            super("JFrame");
            WindowListener l_windowListener = new WindowAdapter() {
                public void windowClosing(final WindowEvent p_evt)
                    DragTest.this.dispose();
                public void windowClosed(final WindowEvent p_evt)
                    System.exit(0);
            MouseListener l_mouseListener = new MouseAdapter() {
                public void mouseEntered(final MouseEvent p_evt)
                    System.err.println(">>> Mouse Entered: " + ((Component)p_evt.getSource()).getName() );
                public void mouseExited(final MouseEvent p_evt)
                    System.err.println(">>> Mouse Exited: " + ((Component)p_evt.getSource()).getName() );
            JPanel l_panel1 = new JPanel();
            l_panel1.setLayout( new BorderLayout(50,50) );
            l_panel1.setName("JFrame Panel");
            l_panel1.addMouseListener(l_mouseListener);
            JButton l_button = null;
            l_button = new JButton("JFrame North Button");
            l_button.setName(l_button.getText());
            l_button.addMouseListener(l_mouseListener);
            l_panel1.add(l_button, BorderLayout.NORTH);
            l_button = new JButton("JFrame South Button");
            l_button.setName(l_button.getText());
            l_button.addMouseListener(l_mouseListener);
            l_panel1.add(l_button, BorderLayout.SOUTH);
            l_button = new JButton("JFrame East Button");
            l_button.setName(l_button.getText());
            l_button.addMouseListener(l_mouseListener);
            l_panel1.add(l_button, BorderLayout.EAST);
            l_button = new JButton("JFrame West Button");
            l_button.setName(l_button.getText());
            l_button.addMouseListener(l_mouseListener);
            l_panel1.add(l_button, BorderLayout.WEST);
            l_button = new JButton("JFrame Center Button");
            l_button.setName(l_button.getText());
            l_button.addMouseListener(l_mouseListener);
            l_panel1.add(l_button, BorderLayout.CENTER);
            JButton l_actionButton = l_button;
            Container l_contentPane = this.getContentPane();
            l_contentPane.setLayout( new BorderLayout() );
            l_contentPane.add(l_panel1, BorderLayout.NORTH);
            JPanel l_panel2 = new JPanel();
            l_panel2.setName("JDialog Panel");
            l_panel2.addMouseListener(l_mouseListener);
            l_panel2.setLayout( new BorderLayout(50,50) );
            l_panel2.add( new JButton("JDialog North Button"),  BorderLayout.NORTH  );
            l_panel2.add( new JButton("JDialog South Button"),  BorderLayout.SOUTH  );
            l_panel2.add( new JButton("JDialog East Button"),   BorderLayout.EAST   );
            l_panel2.add( new JButton("JDialog West Button"),   BorderLayout.WEST   );
            l_panel2.add( new JButton("JDialog Center Button"), BorderLayout.CENTER );
            final JDialog l_dialog = new JDialog(this, "JDialog", true);
            WindowListener l_windowListener2 = new WindowAdapter() {
                public void windowClosing(WindowEvent p_evt)
                    l_dialog.dispose();
            l_dialog.addWindowListener(l_windowListener2);
            l_dialog.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
            l_dialog.getContentPane().add(l_panel2, BorderLayout.CENTER);
            l_dialog.pack();
            Action l_action = new AbstractAction() {
                { putValue(Action.NAME, "Perform Action (open dialog)"); }
                public void actionPerformed(final ActionEvent p_evt)
                    l_dialog.setVisible(true);
            l_actionButton.setAction(l_action);
            this.addWindowListener(l_windowListener);
            this.pack();
            this.setLocation(100,100);
            this.setVisible(true);
            l_dialog.setVisible(true);
    }(Too bad blank lines are stripped, eh?)
    Thanks in advance for any insights you may be able to provide.
    ---Mark

    I guess we can think of this as one problem. When mouse dragged, JFrame also (Parent) receives events. If i understood correctly, what happens here is, Modal dialog creates its own event pump and Frame will be having its own. See the source code of Dialog's show() method. It uses an interface called Conditional to determine whether to block the events or yield it to parent pump.
    Here is the Conditional code and show method code from java.awt.dialog for reference
    package java.awt;
    * Conditional is used by the EventDispatchThread's message pumps to
    * determine if a given pump should continue to run, or should instead exit
    * and yield control to the parent pump.
    * @version 1.3 02/02/00
    * @author David Mendenhall
    interface Conditional {
        boolean evaluate();
    /////show method
        public void show() {
            if (!isModal()) {
                conditionalShow();
            } else {
                // Set this variable before calling conditionalShow(). That
                // way, if the Dialog is hidden right after being shown, we
                // won't mistakenly block this thread.
                keepBlocking = true;
                if (conditionalShow()) {
                    // We have two mechanisms for blocking: 1. If we're on the
                    // EventDispatchThread, start a new event pump. 2. If we're
                    // on any other thread, call wait() on the treelock.
                    if (Toolkit.getEventQueue().isDispatchThread()) {
                        EventDispatchThread dispatchThread =
                            (EventDispatchThread)Thread.currentThread();
                           * pump events, filter out input events for
                           * component not belong to our modal dialog.
                           * we already disabled other components in native code
                           * but because the event is posted from a different
                           * thread so it's possible that there are some events
                           * for other component already posted in the queue
                           * before we decide do modal show. 
                        dispatchThread.pumpEventsForHierarchy(new Conditional() {
                            public boolean evaluate() {
                                return keepBlocking && windowClosingException == null;
                        }, this);
                    } else {
                        synchronized (getTreeLock()) {
                            while (keepBlocking && windowClosingException == null) {
                                try {
                                    getTreeLock().wait();
                                } catch (InterruptedException e) {
                                    break;
                    if (windowClosingException != null) {
                        windowClosingException.fillInStackTrace();
                        throw windowClosingException;
        }I didn't get exactly what is happening but this may help to think further

  • Event structure does not capture mouse click event on toolbar activeX control

    Hi
    We have a toolbar activeX control on FP.  It works perfectly on my computer, but on my coworkers deskyop,  somehow the event structure doesn't capture mouse click event.
    Any idea?  Thanks a lot for any help.
    Anne

    It's a standard activeX control.  I attach a simple vi .
    thanks  for any help.
    Attachments:
    toolbar test.vi ‏41 KB

  • How to detect mouse click event?

    Hello,
    I would like to have a vi to detect left, right and no mouse click. I mean that in the vi attached, Button2 should be 0 (no click), 1 (left c.) or 2 (right c.) depending on the event occured in i-1. cycle. My vi is the modyfied version of the one found here:
    http://www.ni.com/example/27663/en/
    Sometimes it works fine, but another time nothing happens when I click.
    I think the main problem is with the execution times at the for loop and event structure.
    Could you help me how to deal with the problem?
    Thanks you!
    Attachments:
    mouse1.vi ‏12 KB

    Hi VampireEmpire,
    Your For loop iterates twice. If an event occures during first iteration everything is fine - Button 2 refreshes during second iteration. But what happens when an event occures during second iteration? Does Button 2 have a possibility to refresh? 
    1. Do you see the problem now?
    2. And if you do - do you really need For loop? I would suggest you trying removing it and connecting shift register to the while loop.
    Bluesheep

  • Trying to detect mouse over event

    Hi,
    I want to be able to detect when the mouse is hovering over a
    movie clip and continuously move a movieslip if it is. I tried a
    onRollOver callback function but this only fires once when you
    rollver the movieclip. Any ideas? TA

    I need to do a similar thing, except that I'm trying to find
    a way to to detect when the mouse is anywhere over the stage.
    Specifically, I'm creating a main movie that loads and cycles
    through a series of banners. If the mouse rolls anywhere over the
    movie, it should stop rotating the banners until the mouse rolls
    out again. I'm using setInterval to rotate the banners every 15
    seconds, and that works just dandy. Detecting when the mouse is
    over the stage while not interfering with the interactivity of the
    loaded banner is what I'm having trouble with. I tried covering the
    stage with a big movieclip/button to use onRollOver, but that
    interfered with the interactivity of the SWFs being loaded into the
    movie (whichever is on top functions and whichever is below does
    not.)
    So next, I tried making rollOver functions on the containers
    that the SWFs are loading into, since they cover the whole stage
    anyway, but that code also interfered with the interactivity that
    is in each SWF, as if defining a rollOver for it from the main
    movie overrides any interactivity in the SWF. That didn't make
    sense to me, but, anyway, it didn't work either.
    Soooo, I tried writing a code to detect the mouse location:
    function mousecheck() {
    if (_xmouse>=0 && _xmouse<=950 &&
    _ymouse>=0 && _ymouse<=220) {
    clearInterval(id);
    if (_xmouse<0 || _xmouse>950 || _ymouse<0 ||
    _ymouse>220) {
    id = setInterval(rotate_banners, 1500);
    which might work, I could figure out how to call the function
    continuously to "watch" the mouse. I'm already using setInterval to
    rotate through the banners.
    Does anyone have any ideas about what might be a way to
    achieve this task?
    Thanks you for your help in advance!

  • Windows 7 will not detect mouse and keyboard during first log in (BOOT CAMP)

     

    1. If your Registry was corrupted during the uninstall/crash, you can run into issues. Do you have a Windows backup (not a Time Machine backup) that you can restore to.
    2. You can first attempt a startup repair, and may have to rebuild your BCD. If the programs you were installing had associated HW, depending on your Windows version, you may need to use bootrec.exe. There is a MS article about it.
    3. You may end up reinstalling bootcamp drivers (not Windows), to regain trackpad/keyboard functionality.
    4. If Windows does come up and you cannot use the built-in keyboard/trackpad, please try a wired USB keyboard/mouse to see if that works.

  • Backspace not detected as KeyDown Event

    Hi
    I'm trying to determine if the back space is pressed on my WPF. And I'm getting no where!
    My code (which is the event handler for the KeyDown event for a textbox)
    private void CompanyName_KeyDown(object sender, KeyEventArgs e)
    MessageBox.Show(e.Key.ToString());
    If I press a number, return (enter), letter or even a function key (F2, F3 etc) it works. But, delete, backspace and spacebar do not cause the event to fire.
    Any idea why?
    Dave

    Hey DaveRook, I hope you're fine.
    I believe you may check the following approach:
    if (Keyboard.IsKeyDown(Key.Back)) //Also "Key.Delete" is available.
    //Your code goes here..
    Please, mark my reply as Answer if it helps or vote it up if it gives a key to the solution.
    Thanks in advance and good luck.
    Ahmed M. Gamil
    "It is not titles that honor men, but men that honor titles."

  • RIGHT_MOUSE_UP event not detected

    Hi,
    I have an adobe creative cloud account.
    My flashgame does not detect the RIGHT_MOUSE_UP  event when test-published in FLASH Professional CC or FLASH CS6.
    The same code however does work with the flash player in my browser and when I publish the SWF and start it outside of the Development Enviroment.
    All versions should be 11.7 as far as I can tell.
    Does anybody know whats going on?
    Thanks in advance

    Thank you very much for you're awnser.
    I'm not absolutely sure I understand you though.
    I have no difficulty publishing directly to the browser.
    When I publish directly to the Browser everything works fine, it is just in the test Enviroment in which the RIGHT_MOUSE_UP event is not detected.
    It detects the RIGHT_MOUSE_DOWN event without problems.
    Publishing and then executing from windows also works fine, it is just when the IDE test-publishes that the problem occurs-.
    My main reason for not publishing to the browser is because I can no longer see the Output of the "trace" commands, which I require for debugging.
    I have tried changing the flash version for which my IDE publishes, but regardless of which version I choose the problem persists.
    Im not absolutely certain what you mean by "the flash ide /"captures/" that right-click when testing".
    Is there anyway to prevent this?
    Or is there at least a way with which I could see the Output of my "trace" commands when publishing to the browser?
    Thank you very much for you're helpfull advice, I tried contacting adobe but all they told me was "sorry we don't offer support for that kind of problem".

  • Problem with MOUSE OUT event in complex MCs

    Hi,
    I've got a problem with detecting mouse out event (AC3)
    appearing when MC
    contains other embeded MCs. The Event.MOUSE_OUT seems to be
    unusefull
    because every MC attached to parent triggers this event. I
    can't turn off
    mouse listening for these objects because they are a kind of
    buttons
    (thumbnails in picture gallery). So MOUSE_OUT event is
    triggered even when
    we are still inside parent MC. More over - MC has irregular
    shape which
    makes impossible to check mouse position and compare it 'by
    hand' with
    object with not rectangular boundary. Does anybody know how
    to solve this
    issue ?
    Regards,
    Marek

    > yes this is expected behaviour with MOUSE_OUT, which is
    why there is
    > another
    > event ROLL_OUT, which as Flash help says, "...is to
    simplify the coding of
    > rollover behaviors for display object containers with
    children."
    Thanks a lot Craig !
    Now it works fine.

  • JPopupMenu disappears when mouse exits (too quickly)

    Hi,
    I am trying to figure out a way to delay the mouse exit event to not make my JPopupMenu disappear so fast. I have a panel that allows the user to left click to get a JPopupMenu, and that works great but the problem becomes if the user DOES NOT move his/her mouse diagonally downward/leftward into the JPopupMenu it will disappear. So once the popup is visible it very frequently will just disappear right away if the user wiggles his mouse a tiny bit when he/she is trying to put the mouse inside it.
    What I want to do is allow a delay of about 1.5 seconds before the the popup can be hidden. Hence a user clicks on a point and get the JPopupMenu and then even if they move their mouse off of the JPopupMenu it won't disappear. So it is guarenteed to be visible for 1.5 seconds at the minimum.
    Any ideas?

    they shouldn't disappear on mouse exit events at all... unless you are explicitly using a mouse exit listener to tell the menu to hide. In which case, you can use a Timer or something to hide it after a delay.

  • Mouse motion events

    For some reason my custom JComponent or cutom Jpanel do not detect any mouseMotion events. Does anyone know why that is?
    I have a class like the following
    public class GeometryPanel  extends JComponent implements MouseInputListenerin my main class (the frame class) I have the following
             JFrame frame = new JFrame();
         JPanel p = new MyPanel();
         JComponent geometryPanel;
         JComponent buttonPanel = new ButtonPanel(this);
         public MainWindow()
              geometryPanel = new GeometryPanel(this,600, 600);
              setupGUI();
              displayFrame();
         public void setupGUI()
               p.setBackground( Color.white );
              p.setPreferredSize(new Dimension(width, height));
              geometryPanel.setPreferredSize(new Dimension(600, 600));
              buttonPanel.setPreferredSize(new Dimension(620, 80));
               p.add( geometryPanel );
               p.add( buttonPanel );
         public void displayFrame()
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setContentPane(p);
              frame.pack();
              frame.setLocationRelativeTo(null);
              frame.show();
         }For some reason all of the mouse pressed events are caught, but not the motion events. They are not fired.

    Ah I got it, thank you. Forgot to add the mouse motion listener next to the mouse listner

  • Remmina not transmitting mouse wheel to VNC session

    Hi,
    I have just noticed that remmina is not transmitting mouse wheel events to VNC session. Never tried RDP, so I don't know if this is also affected.
    First question: Is it only on my system or a general problem on Arch ?
    If it is a general problem on Arch ...
    I did a bit research abot this subject area, and I found some bug reports in multiple distros, but they are all marked as solved. So I think that it is fixed upstream. Otherwise the distros could not mark it as solved, right ?
    If the package maintainer should read this ... is there a plan to update this package in near future ?
    Thanks and Regards,
    Markus

    Usability bugs. The most annoying one was the size of the remmina window that was "never" right. And clicking the "1" button (top left) did unpredictable things. In most cases the window was maximised to full screen height leaving black bars above and below. The bug seems to appear less and less. I promise I will file a bug when I experience it again :-)
    Crashes were always rare in my case.
    But here's not the right place to lament around.

  • How can I capture mouse click events on BSP or Web Dynpro ABAP Screen

    hi Guys,
    Currently we have a user inactivity problem,
    the requirement is: if user is clicking on BSP/Web Dynpro ABAP screen, he/she is considered active. so we need an mechanism to capture the mouse click event.
    Using Firebug, we found that this js is in the iframe which contains BSP/web dynpro scrren: /sap/public/bc/ur/nw5/js/languages/urMessageBundle_en.js
    we want to find this js file & put in some javascript code to track user's mouse click, but i cannot find it on server.
    while in ie if we type http://host:port/sap/public/bc/ur/nw5/js/languages/urMessageBundle_en.js
    this file can be downloaded, means this file is there.
    Any one can help on this issue? find the js file or another way to capture the mouse click event.
    Thanks a lot with points!

    Hi  Feng Guo,
                        We can not capture mouse click events on Web Dynpro ABAP Screen . I am not sure about BSP. But as for as I know the portal keep active the iViews until unless mouse clicks happens.
    But for your problem I think you can get solution by setting iView Expiration to some more time period.
    Regards,
    Siva

  • KeyListener does not capture Arrow key Events in textField

    Love................
    I added a key listener to TextField it does not detect
    Arrow Keys events in keyTyped, KeyPressed,KeyReleased methods
    why?????
    I want to shift focus from a textfield to other component
    on capturing Arrow key Pressed How

    Here is a Java demo where it works since it is not a printable character you must get the keyCode:
    http://java.sun.com/docs/books/tutorial/uiswing/events/example-swing/index.html#KeyEventDemo
    public class KeyEventDemo ... implements KeyListener ... {
    ...//where initialization occurs:
         typingArea = new JTextField(20);
         typingArea.addKeyListener(this);
    /** Handle the key typed event from the text field. */
    public void keyTyped(KeyEvent e) {
         displayInfo(e, "KEY TYPED: ");
    /** Handle the key pressed event from the text field. */
    public void keyPressed(KeyEvent e) {
         displayInfo(e, "KEY PRESSED: ");
    /** Handle the key released event from the text field. */
    public void keyReleased(KeyEvent e) {
         displayInfo(e, "KEY RELEASED: ");
    protected void displayInfo(KeyEvent e, String s){
         char c = e.getKeyChar();
         int keyCode = e.getKeyCode();
         int modifiers = e.getModifiers();
         tmpString = KeyEvent.getKeyModifiersText(modifiers);
         ...//display information about the KeyEvent...
    }

  • Mouse clicks not detected on JTabbedPane

    Hi all,
    I have a JPanel placed inside a JTabbedPane. I want to double-click on the JPanel and bring up a JDialog. This works fine if the JPanel is not in a JTabbedPane, but if it is on a JTabbedPane, then the mouse clicks are not detected. I'd greatly appreciate any help you can give me.

    Here is a sample program that seems to work:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class TestInternalFrame extends JFrame
         public TestInternalFrame()
              JDesktopPane desktop = new JDesktopPane();
              setContentPane( desktop );
              JInternalFrame internal = new JInternalFrame( "Internal Frame" );
              desktop.add( internal );
              internal.setLocation( 50, 50 );
              internal.setSize( 300, 300 );
              internal.setVisible( true );
              JTabbedPane tabbedPane = new JTabbedPane();
              internal.getContentPane().add(tabbedPane);
              tabbedPane.setPreferredSize( new Dimension(300, 200) );
              JPanel panel = new JPanel();
              tabbedPane.add( "Empty Panel", panel );
              panel.addMouseListener( new MouseAdapter()
                   public void mouseClicked(MouseEvent e)
                        System.out.println(e.getClickCount());
         public static void main(String args[])
    TestInternalFrame frame = new TestInternalFrame();
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.setSize(400, 400);
    frame.setVisible(true);

Maybe you are looking for

  • Null Pointer Exception on Dynamic vo when drag as dynamic table in popup

    Hi All, i am using jdev version 11.1.1.5.0. i have create one dynamic vo and drag as dynamic table. it is running fine but when i drag it in popupwindow and when i click on button on action listener change query of dynamic vo then following error occ

  • Doubts in Statspack

    Hi, I have one small doubt (crosschecking) in Statspack. Prior to 9i, whether a wait event needs to be considered or not that depends on following formula : response time = service time + wait time = cpu used by session + wait time = cpu used by sess

  • Protecting file/folder names/labels

    Anyone know of a way to protect, lock or "freeze" file/folder names/labels without locking the associated file or folder? Thanks, JD

  • Grid setup

    Hello i habe only one node for now i am willing to install oracle 11gR2 one node option, and use asm what option of grid infrastructure shall i use:? -For standalone -For cluster and select only the one node that i have then i add other node later ?

  • Creating REMADV idoc- payment advice

    Hi Experts, I want to generate REMADV idoc after the payment run, can anyone please suggest the configuration need. Thanks&Regards Srinivas