Mouse events during Thread.sleep

hi.
I have an applet .
I have a alghoritm simulator.
Everytime I find a solution I call the method Thread.sleep .
I want to pause the application and I create a JToggleButton Pause .
When I press the Pause during sleep mouse event are managed at the end of alghoritm.
How can I manage mouse events during sleep?

All UI events (such as mouse events) occur on the event dispatch thread (EDT).
That means if you sleep on the EDT, you lock up the UI. For this reason, you shouldn't be sleeping on the EDT.
I'm not sure what your sleep is trying to do but you need to manage your threads a little more carefully. For instance, any time consuming process which is invoked as a result of a UI event needs to be fired on a new thread to prevent the UI freezing. The fun starts when you have to update the UI as a result of that process, because you should then hook back onto the EDT to avoid the risk of deadlock.
Some utility classes are provided, such as SwingUtilities, and other example code is provided on Sun's site, such as SwingWorker - but if you do much UI work you'll probably end up with your own core set of threading tools and so on to make life easier.

Similar Messages

  • Keyboard and mouse events during screen sharing

    I use OS X 10.6.8, my mom has 10.5.(8?).
    Screen sharing used to work fine. I am always viewing her screen.
    Lately, none of my keyboard presses or mouse clicks make it through the connection to her machine. I can 'influence' but not really control the placement of her cursor as viewed on my screen. She never sees the pointer move from wherever it was before I started trying to move it. I can see her screen fine, and even see some frame rate if she plays a video from an email message (but I don't get the audio stream). We can't continue talking while the video is playing though because our voice connection has too many dropouts.
    She did change from using Comcast to using AT&T Uverse several months ago. I can't remember exactly when the troubles started, but it could have been at the time of that switch. She is getting a lower speed connection than she used to.
    Are these issues strictly a problem of a too-slow connection, or is there something else to try. I'm most concerned about the keyboard and mouse loss, since that means I have to describe every action to her instead of doing anything myself. I can live without viewing videos over a screen sharing link...

    Hi,
    It is worth doing  Speed check at both ends
    http://www.speedtest.net/
    It may also pay to open the Connection Doctor (Video Menu) during a Audio or Video chat and checking the Bit rate and Framerate (on Video).
    iChat in 1-1 Video needs "Real World" speed of 256kbps  (it will manage according to Apple at 128kbps).
    This Min of 128kbps is the min for Screen Sharing as well.
    The Connection Doctor will show you what iChat is using (your Bit rate) NOT what the Internet Speed is measured at.
    It will be closer to the Upload Speed you have.
    iChat will tend to settle closer to the slower speed of whichever Buddy has the slowest Upload (plus a margin for variances in the ISP's feed/service)
    If the variances in the Internet Speed from the ISP varies too much then iChat will have difficulties.
    It will drop Audio (As far as you as concerned) as it will start dropping frames to smooth the video out.
    For this reason it can pay to go to iChat > Preferences > Video Section and try the Bandwidth Limit at 500kbps  (If for instance you have a 10Mbps Upload a 5% variance can be a whole 500kbps)
    With both ends at 500kbps you can be below the Variance factor.
    Try 200kbps if there still appear to be problems.
    NOTE:-
    iChat's responses are determined by the Internet Speed (Or at least the portion that computer is getting = Bandwidth) and what else the computer is doing.
    Depending on the Mac and it's Processor and the apps running at the time iChat may not get a decent use of the Processor.  (It is set to use it "last" a it were so Downloading, Playing Video elsewhere, or setting background tasks (Anit Virus scans, iMovie Rendering) may impinge on free Processor cycles).
    Try to eliminate as much as possible.
    <
    9:19 PM      Tuesday; July 19, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • How to deal with the mouse events when the thread is running

    Hi everybody,
    I have a problem with my program.
    Now I want to present a picture for some time in the Canvas,then automatically clear the screen, but when the user press the mousebutton or keybutton, I want to stop the thread and clear the screen.
    How can I receive the mouse event when the thread is running?
    Thanks,

    I use my code in a GUI applet.
    I try to use the code tag, it's the first time.
                   Image im=sd.getStimulus(obj);
                   if(pos==null){
                        g.drawImage(im, (w-im.getWidth(null))/2,(h-im.getHeight(null))/2,null);
                   }else{
                        g.drawImage(im, pos.x,pos.y,pos.w,pos.h,null);
                   try{
                        sleep(showtime);
    //                    Thread.sleep(showtime);
                   }catch(InterruptedException e){}
                   if(pos==null){
                        g.clearRect((w-im.getWidth(null))/2,(h-im.getHeight(null))/2,im.getWidth(null),im.getHeight(null));
                   }else{
                        g.clearRect(pos.x,pos.y, pos.w, pos.h);
                   }

  • Get mouse position during Custom UI Draw event?

    I am building a Custom UI for one of my plugin effect.
    I want to get the mouse position during the Custom UI Draw event (PF_Event_DRAW), but cannot manage to get it.
    From what I understand, it seems we can only get the mouse position during the events PF_Event_DRAG, PF_Event_DO_CLICK, and PF_Event_ADJUST_CURSOR.
    I tried to use PFAppSuite4::PF_GetMouse() too, but this resulted in the error message "After Effects error: internal verification failure, sorry! {PF_GetMouse can only be called during valid events.}".
    Therefore I want to store the mouse position during PF_Event_ADJUST_CURSOR, and use it later during PF_Event_DRAW.
    Where can I store those values in a "clean" way (ensuring there will not be conflicts if two instances of the same effect are running, etc)?
    Or is there an easier method to get the mouse position during a Custom UI Draw event?

    //SequenceDataVars is the name of your data structure
    //this is how you create the sequence data
    out_data->sequence_data = PF_NEW_HANDLE(sizeof(SequenceDataVars));
    SequenceDataVars *seqData =
    (SequenceDataVars*)PF_LOCK_HANDLE(out_data->sequence_data);
    //and now you can store stuff in it.
    seqData->var1 = 7;
    //after it's created, on other calls, you just do a simple cast
    SequenceDataVars *seqData = *(SequenceDataVars **)out_data->sequence_data;
    seqData->var1 = 100;
    //this is how you delete it. (if you don't delete it, it will be saved with
    the project, and loaded on the next session. (if you want)
    PF_DISPOSE_HANDLE(out_data->sequence_data);
    there's more to know, so look up SequenceSetup, SequenceSetdown, ect in the
    sample project.

  • Don't want random keyboard & mouse events to wake from sleep

    is there any way to prevent a random keyboard press or mouse movement from waking up the computer? a terminal setting or something? ideally, i'd just like to use the power button to do this--or at the very least to completely disable the mouse's ability to wake the machine, and specify a certain key or something.
    seems like an obvious setting that's missing...or that i'm overlooking...?
    thanks!
    various Macs   Mac OS X (10.4.8)  

    markhimself wrote:
    Is there any way to disable the mouse from waking from sleep mode? Additionally, can you disable the mouse from waking the display from display sleep only? And is this done the same way?
    Thanks.
    If it's a BlueTooth mouse you can uncheck the option in the Keyboard & Mouse preferences.

  • Mouse Events "Falling Through" During Window Activation

    I'm implementing a "tool pallette" in my application (much like tools in an application like Photoshop) and I want the user to be able to immediately click on options on this pallete without having to make the window active. Since Swing doesn't have an explicit "Pallete" window that would give this to me for free, I'm assuming I need to subclass JDialog to make this happen.
    Even if window activation still must happen, it's crucial that the user only needs to click once to press the button on an inactive window.
    I know I can detect WindowEvents like WINDOW_ACTIVATED by simply adding my own window listener, but I don't know how I'd go about having mouse events "fall through" the window listeners and cause the appropriate action on the underlying component. It's almost as if I need to tell the window itself to listen for nothing.
    I thought glass planes may be the answer, but that doesn't seem to be what's preventing the intial click in an inactive window from falling through to the underlying component.
    Any thoughts, comments, or experiences regarding this are greatly appreciated!

    The solution to this problem was posted in the Swing forum. Turns out to be a simple difference of JWindow and JDialog, but a difference I wasn't seeing under all L&Fs (i.e., Windows L&F handles JDialog properly, MacOSX (Aqua) L&F seems to treat it like any other window... I've filed a bug with them).

  • Repaint() being delayed by Thread.sleep()

    Hello, I am programming a Memory-like card game, where the user picks cards and if they match they stay flipped over, but if they don't match the cards will be displayed for a second and then flipped back over. However, I am running into a problem when the cards do not match, the game will wait (using Thread.sleep()) and then flip the cards back over. The problem is that the second card picked, that is determined to not be a match, is not showing the face before the cards are returned to the hidden state. I think that it is being flipped twice in a row at the end of the sleep(), therefore never actually displaying the front of the card. I have tried putting repaint() everywhere, and there is one before the sleep(), but it still doesn't seem to work properly. Here is the code for my mouse clicked event. Thanks for any help!
      public void mouseClicked(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();
        Card temp = null;
        for (int i = 0; i < 52; i++) {
          temp = cards.getCard(i);
          if (temp.contains(x, y)) {
            if (temp.isFront() == true)
              return;
            temp.swapImg();
            this.repaint();
            if (flipped == null) {
              flipped = temp;
            } else {
              if (temp.getVal() == flipped.getVal()) {
                // we have a pair
              } else {
                // cards don't match.. start over
                try {
                  Thread.sleep(500);
                } catch (InterruptedException ie) {
                  System.out.println("Thread was interrupted!\r\n");
                temp.swapImg();
                flipped.swapImg();
              flipped = null;
            break;
      }

    Don't use Thread.sleep() inside a Listener. You are blocking the EDT which prevents the GUI from repainting itself.
    Use a Swing Timer to schedule the flipping of the cards.

  • Need More Mouse Events

    [http://forums.sun.com/thread.jspa?messageID=10811388|http://forums.sun.com/thread.jspa?messageID=10811388]
    During search over net I found the above thread and it seems to be describing the same problem which I am also facing. For my application also I need to capture all the mouse events while dragging. I tried the soluiotn mentioned at this thread to solve this problem by overrinding the below method in several ways:
    protected AWTEvent coalesceEvents(AWTEvent existingEvent,AWTEvent newEvent);
    Even after several attempts, I could not succeed. Can you please suggest how to do that. I was not able to reply to above thread so creating this new thread.
    Thanks

    I wanted to see if a timer based approach does indeed produce a smoother curve than just simply listening for mouse drag events. What I came up with below was the resulting test code. Lo and behold, using a timer does indeed produce a smoother curve. But it wasn't because it was capturing more mouse positions, it was because it was capturing less. Ain't that a kicker? Another interesting thing is that according to the source code, coalesceEvents is a no-op. The documentation, however, would have you believe that it coalesces mouse events as I thought it did.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.GeneralPath;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.BorderFactory;
    public class Test {
        private static class TimerBasedPanel extends JPanel implements MouseListener {
            private GeneralPath line;
            private Timer mousePosQuerier;
            private Component mouseEvtSource;
            private int pointCount;
            public TimerBasedPanel(Component mouseEventSource) {
                mousePosQuerier = new Timer(15, new ActionListener() {
                    Point lastMousePoint = new Point(-1, -1);
                    public void actionPerformed(ActionEvent e) {
                        Point p = MouseInfo.getPointerInfo().getLocation();
                        if (p.x != lastMousePoint.x || p.y != lastMousePoint.y) {
                            lastMousePoint.setLocation(p);
                            SwingUtilities.convertPointFromScreen(p, mouseEvtSource);
                            line.lineTo(p.x, p.y);
                            pointCount++;
                            repaint();
                mouseEvtSource = mouseEventSource;
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if(line != null) {
                    ((Graphics2D) g).draw(line);
            public void mousePressed(MouseEvent e) {
                line = new GeneralPath();
                line.moveTo(e.getX(), e.getY());
                pointCount = 1;
                mousePosQuerier.start();
            public void mouseReleased(MouseEvent e) {
                mousePosQuerier.stop();
                repaint();
                System.out.println("Timer Based, Points Captured: " + pointCount);
            public void mouseEntered(MouseEvent e){}
            public void mouseExited(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
        private static class DragEventsPanel extends JPanel
                implements MouseListener, MouseMotionListener{
            private GeneralPath line;
            private int pointCount;
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if(line != null) {
                    ((Graphics2D) g).draw(line);
            public void mousePressed(MouseEvent e) {
                line = new GeneralPath();
                line.moveTo(e.getX(), e.getY());
                pointCount = 1;
            public void mouseDragged(MouseEvent e) {
                pointCount++;
                line.lineTo(e.getX(),e.getY());
                repaint();
            public void mouseReleased(MouseEvent e){
                System.out.println("DragEvent Based, Points Captured: " + pointCount);
            public void mouseEntered(MouseEvent e){}
            public void mouseExited(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
            public void mouseMoved(MouseEvent e) {}
        public static void main(String args[]) {
            JFrame frame = new JFrame();
            JPanel drawPanel = new JPanel() {
                @Override
                protected AWTEvent coalesceEvents(AWTEvent existingEvent,
                                                  AWTEvent newEvent) {
                    if(newEvent.getID() == MouseEvent.MOUSE_DRAGGED) {
                        return null;
                    }else {
                        return super.coalesceEvents(existingEvent, newEvent);
            TimerBasedPanel timerPanel = new TimerBasedPanel(drawPanel);
            DragEventsPanel dragPanel = new DragEventsPanel();
            drawPanel.setBorder(BorderFactory.createTitledBorder("Draw here"));
            timerPanel.setBorder(BorderFactory.createTitledBorder("Uses a timer"));
            dragPanel.setBorder(BorderFactory.createTitledBorder("Listens for drag events."));
            drawPanel.addMouseListener(timerPanel);
            drawPanel.addMouseListener(dragPanel);
            drawPanel.addMouseMotionListener(dragPanel);
            frame.setLayout(new java.awt.GridLayout(0,3));
            frame.add(drawPanel);
            frame.add(timerPanel);
            frame.add(dragPanel);
            frame.setSize(600,200);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }Edited by: Maxideon on Sep 16, 2009 9:56 PM
    Minor error, but now fixed.

  • Getting Key Events during animation loop

    I'm having a problem recieving Key events during my animation loop. Here is my example program
    import java.awt.*;
    import java.awt.image.BufferStrategy;
    import javax.swing.JPanel;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import java.util.ArrayList;
    import java.awt.event.*;
    import java.util.Iterator;
    import GAME.graphics.Animation;
    import GAME.sprites.MainPlayer;
    import GAME.util.MapData;
    import GAME.input.*;
    public class ImageTest extends JFrame {
        private static final long DEMO_TIME = 20000;
        private Animation      anim;
        private MainPlayer     mPlayer;
        private MapData               mapData;
        private InputManager      inputManager;
        private GameAction moveLeft;
        private GameAction moveRight;
        private GameAction exit;
        public ImageTest()
         requestFocus();
         initInput();
         setSize(1024, 768);
         setUndecorated(true);
         setIgnoreRepaint(true);
         setResizable(false);
         loadImages();
         anim = new Animation();
            mPlayer = new MainPlayer(anim);
            setVisible(true);
            createBufferStrategy(2);
            animationLoop();
         // load the player images
         private void loadImages()
              // code that loads images...
         // Initialize input controls
         private void initInput() {
            moveLeft = new GameAction("moveLeft");
            moveRight = new GameAction("moveRight");
            exit = new GameAction("exit",
                GameAction.DETECT_INITAL_PRESS_ONLY);
            inputManager = new InputManager(this);
            inputManager.setCursor(InputManager.INVISIBLE_CURSOR);
            inputManager.mapToKey(moveLeft, KeyEvent.VK_LEFT);
            inputManager.mapToKey(moveRight, KeyEvent.VK_RIGHT);
            inputManager.mapToKey(exit, KeyEvent.VK_ESCAPE);
        // Check player input
        private void checkInput(long elapsedTime) {
            if (exit.isPressed()) {
                System.exit(0);
            if (mPlayer.isAlive()) {
                float velocityX = 0;
                if (moveLeft.isPressed()) {
                    velocityX-=mPlayer.getMaxSpeed();
                if (moveRight.isPressed()) {
                    velocityX+=mPlayer.getMaxSpeed();
                mPlayer.setVelocityX(velocityX);
        // main animation loop
        public void animationLoop() {
            long startTime = System.currentTimeMillis();
            long currTime = startTime;
            while (currTime - startTime < DEMO_TIME) {
                long elapsedTime =
                    System.currentTimeMillis() - currTime;
                currTime += elapsedTime;
                checkInput(elapsedTime);
                mPlayer.update(elapsedTime);
                // draw and update screen
                BufferStrategy strategy = this.getBufferStrategy();
                Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
                if (!(bgImage == null))
                     draw(g);
                     g.dispose();
                     if (!strategy.contentsLost()) {
                         strategy.show();
                // take a nap
                try {
                    Thread.sleep(20);
                catch (InterruptedException ex) { }
        public void draw(Graphics g) {
            // draw background
            if (bgImage != null)
                         // draw image
                 g.drawImage(mPlayer.getImage(), (int)mPlayer.getX(), (int)mPlayer.getY(), null);
    }My InputManager implements KeyListener. When running print statements on my Key events, they are not being called until after the animation demo is done running. Can someone help me with getting the Key events to update during the animation loop? Thank you!

    I've used the post from Abuse on the following thread with success. Maybe it will clue you in to what you might be doing wrong:
    http://forum.java.sun.com/thread.jsp?forum=406&thread=498527

  • Exception catching in event processing thread

    Hello!
    How to catch exceptions occurring in event processing thread during repaints, mouse & keyboard event processing etc.? All uncatched exceptions displayed in screen but I need to write them in logfile.
    Anton

    Yes - push your own event processor on to the AWT event queue. See my replies at
    http://forum.java.sun.com/thread.jsp?forum=57&thread=484167
    and
    http://forum.java.sun.com/thread.jsp?forum=57&thread=163020
    Although for two completely different purposes, this technique will also allow you to put your own try/catch around super.dispatchEvent()
    Hope that helps
    Tom

  • Capturing desktop mouse events in java

    hi,
    i want to capture mouse events running outside JVM,how do i get
    it.example if click on some application for opening it.how will i get it in my java prog.
    bye

    There is an example,it works well .
    import java.awt.*;
    public class CatchMouse {
         public static void main(String[] args) {
              int limit=10;
              Point mp=null;
              for(int i=0;i<limit;i++){
                   mp=MouseInfo.getPointerInfo().getLocation();
                   System.out.println(mp.x+","+mp.y);
                   try{
                        Thread.sleep(500);
                   }catch(InterruptedException ie){
    }I hope it can help you.

  • Mouse Events In Web

    Hi,
    I am under migrate my application to web and a lot of problems happens.
    First i am using mouse events in my application and i found a PCJ ( HandleMouseEvent2) in this site
    http://forms.pjc.bean.over-blog.com/ext/http://sheikyerbouti.developpez.com/forms-pjc-bean/menu/
    First My questions :
    1- Is beans working fine with forms?
    2- If i use mouse evnets using PCJ in oracle form this well effect on the network.
    3- I need simple instruction how to implement a java bean with oracle form i read most of threads about how to implement java bean but still no clear thread about instructions a,b,c,d ....etc.
    4- If i bring any jar file this jar file need a special jinitiator version or what ?
    5- What is the best solution to make PCJ working fine with forms?
    A lot of question i appreciate for help.........Thanks
    Regards,
    Edited by: kingadmin on Dec 1, 2010 9:04 AM

    Mouse events it's not working in that bean i go this error
    racle JInitiator: Version 1.3.1.22
    Using JRE version 1.3.1.22-internal Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\habib
    Proxy Configuration: no proxy
    JAR cache enabled
    Location: C:\Documents and Settings\habib\Oracle Jar Cache
    Maximum size: 50 MB
    Compression level: 0
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    q: hide console
    s: dump system properties
    t: dump thread list
    x: clear classloader cache
    0-5: set trace level to <n>
    Loading http://nvs-087673b1bea:8889/forms/java/frmall_jinit.jar from JAR cache
    Loading http://nvs-087673b1bea:8889/forms/java/FormsProperties.jar from JAR cache
    Loading http://nvs-087673b1bea:8889/forms/java/MouseEvents.jar from JAR cache
    proxyHost=null
    proxyPort=0
    connectMode=HTTP, native.
    Forms Applet version is : 10.1.2.0
    [oracle.forms.fd.HandleMouseEvent2] --> HandleMouseEvent20 [class oracle.forms.fd.HandleMouseEvent2]1.0,1.0
    [oracle.forms.fd.HandleMouseEvent2] --> ScrollBox1 [class oracle.ewt.scrolling.scrollBox.ScrollBox]41.0,159.0
    [oracle.forms.fd.HandleMouseEvent2] --> VButton0 [class oracle.forms.ui.VButton]41.0,8.0
    [oracle.forms.fd.HandleMouseEvent2] --> VCheckbox0 [class oracle.forms.ui.VCheckbox]41.0,39.0
    [oracle.forms.fd.HandleMouseEvent2] --> VRadioButton0 [class oracle.forms.ui.VRadioButton]41.0,65.0
    [oracle.forms.fd.HandleMouseEvent2] --> VRadioButton1 [class oracle.forms.ui.VRadioButton]120.0,65.0
    [oracle.forms.fd.HandleMouseEvent2] --> VTextArea0 [class oracle.forms.ui.VTextArea]41.0,96.0
    [oracle.forms.fd.HandleMouseEvent2] --> VComboBox0 [class oracle.forms.ui.VComboBox]41.0,125.0
    [oracle.forms.fd.HandleMouseEvent2] --> VTextArea1 [class oracle.forms.ui.VTextArea]0.0,0.0
    [oracle.forms.fd.HandleMouseEvent2] SetProp CANVAS2 0 0
    [oracle.forms.fd.HandleMouseEvent2] --> found CANVAS2
    [oracle.forms.fd.HandleMouseEvent2] SetProp BL.BEAN 1 1
    [oracle.forms.fd.HandleMouseEvent2] --> found BL.BEAN
    [oracle.forms.fd.HandleMouseEvent2] SetProp BL.PB 41 8
    [oracle.forms.fd.HandleMouseEvent2] --> found BL.PB
    [oracle.forms.fd.HandleMouseEvent2] SetProp BL.CB 41 39
    [oracle.forms.fd.HandleMouseEvent2] --> found BL.CB
    [oracle.forms.fd.HandleMouseEvent2] SetProp BL.RG 41 65
    [oracle.forms.fd.HandleMouseEvent2] --> found BL.RG
    [oracle.forms.fd.HandleMouseEvent2] SetProp BL.RG 120 65
    [oracle.forms.fd.HandleMouseEvent2] --> found BL.RG
    [oracle.forms.fd.HandleMouseEvent2] SetProp BL.TI 41 96
    [oracle.forms.fd.HandleMouseEvent2] --> found BL.TI
    [oracle.forms.fd.HandleMouseEvent2] SetProp BL.LIST1 41 125
    [oracle.forms.fd.HandleMouseEvent2] --> found BL.LIST1
    [oracle.forms.fd.HandleMouseEvent2] SetProp TREE.TREE 41 159
    [oracle.forms.fd.HandleMouseEvent2] --> found TREE.TREE
    [oracle.forms.fd.HandleMouseEvent2] Component clicked:oracle.forms.ui.FormDesktopContainer
    Exception occurred during event dispatching:
    java.lang.NoSuchMethodError
         at oracle.forms.fd.HandleMouseEvent2.handleComponent(HandleMouseEvent2.java:292)
         at oracle.forms.fd.HandleMouseEvent2.access$6000171(HandleMouseEvent2.java:39)
         at oracle.forms.fd.HandleMouseEvent2$2.mouseEntered(HandleMouseEvent2.java:139)
         at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)
         at oracle.ewt.event.tracking.GlassMouseGrabProvider.processMouseGrabs(Unknown Source)
         at oracle.ewt.event.tracking.GlassMouseGrabProvider$Disp._redispatchEvent(Unknown Source)
         at oracle.ewt.event.tracking.GlassMouseGrabProvider$Disp._checkTarget(Unknown Source)
         at oracle.ewt.event.tracking.GlassMouseGrabProvider$Disp._checkTarget(Unknown Source)
         at oracle.ewt.event.tracking.GlassMouseGrabProvider$Disp.mouseEntered(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.processEventImpl(Unknown Source)
         at oracle.ewt.event.tracking.GlassMouseGrabProvider$Proxy.processEventImpl(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.trackMouseEnterExit(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

  • Mouse events don't work on a button from a panel ran in a DLL

    Hi.
    I have a DLL that loads a panel.
    Since it's a DLL I can't do the RunUserInterface() function, because the DLL would be stuck waiting for the panel events.
    I only do the LoadPanel().
    When I click with the mouse on one of the buttons, the pushing down event (simulating the button being pressed) doesn't happen and the callback doesn't run.
    But if I press the tab button until the focus reaches the button and press Enter, the callback of the button is executed.
    An even more interesting aspect is that this happens when I call the DLL on TestStand, but on an application of mine that calls the DLL just for debug everything works fine.
    How can I enable the mouse events?
    Thanks for your help.
    Daniel Coelho
    VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
    Controlar - Electronica Industrial e Sistemas, Lda
    Solved!
    Go to Solution.

    Hello Daniel,
    I got surprised when I read your post, because I am experiencing something almost the same as you do.
    I have a DLL (generated by an .fp instrument driver I wrote) which performs continious TCP communication with the UUT.
    It starts 2 threads, each for reading from one of the 2 different IPs the UUT has.
    Another DLL tests this UUT (with the help of the communication DLL above) by exporting functions to be called by TestStand steps.
    If the second DLL wants to display a CVI panel in order to wait for the user response or displays a popup (MessagePopup, ConfirmPopup, etc), user cannot press the buttons.
    Actually, there is a point your program and mine differ. I call RunUserInterface and the button's callbacks call QuitUserInterface, so the execution continues after a button is pressed. The problem is buttons cannot be pressed. I also tried looping on GetUserEvent  but it did not solve the problem.
    There are 2 findings:
    1. I had a small exe to test my instrument driver DLL and the popups in it worked pretty well (this coincides with Daniel's findings).
    2. We workedaround the problem by shutting down the communication threads in the instrument driver DLL before the popup appears and restrating them afterwards. Although they are separate threads in another DLL, they were somehow blocking user events on another DLL running.
    S. Eren BALCI
    www.aselsan.com.tr

  • Not Running on the Event Dispatch thread, but UI still freezes

    The environment: I am currently working on an application that requires some heavy lifting in response to user input on a UI. To do this I am using a version of SwingWorker that was backported from java 1.6 to java 1.5 in conjunction with a slew of custom threads.
    The problem: I am currently running into an issue where I am not operating on the Event Dispatch thread (checked by doing a javax.swing.SwingUtilities.isEventDispatchThread()) but the UI is still freezing during this section. The operation involves a loop with about 2000 iterations and contains several file accesses. I have thought about how to make a new thread to perform the same operation, but I do not see how it would be any different since as it is I am not on the EDT. The call is being made from doInBackground and specifically the piece that is slowing things down is the File Accesses (2 for every iteration of the loop). At this point I am not sure how to go about resolving the issue. Any one have any suggestions?

    I am not operating on the Event Dispatch threadThat is the problem. Use multiple threads for GUI, which should delegates to the EDT, and your app logic.

  • Event Dispatch Thread Hangs, what is wrong?

    The Event Dispatch Thread Hangs when showing a modal dialog while running a
    SwingWorker Thread.
    I have included my code at the bottom of the page. There are three classes. I have posted a bug report to red hat. But I want to make sure my code is correct.
    My test case just puts the SwingWorker to sleep
    but the problem occurs if I do something real, like connect to a database, etc.
    Also I have tried little different variations of the logic calling
    setVisible(true)/(false) in different places and the same problem occurs.
    It seems to work with Sun JDK, note I am using IcedTea with Fedora Core 8.
    Version-Release number of selected component (if applicable):
    [szakrews@tuxtel ~]$ java -version
    java version "1.7.0"
    IcedTea Runtime Environment (build 1.7.0-b21)
    IcedTea Client VM (build 1.7.0-b21, mixed mode)How reproducible:
    Every couple times.
    javac TestClass2
    java TestClass2eventually it will hang. If it doesn't try again.
    You don't have to wait for the program to finish either.
    The program runs the Dialog 10 times but it never works or fails in the middle, it will either work or fail from the first dialog displayed.
    I have included a thread dump. That is about the most informative information I can get. Neither tracing nor writing a custom ThreadQueue or Drawing Manager to trace events produces any helpful information.
    Actual results:
    The JProccessBar won't move, and the SwingWorker finishes but the done() method is never run. The PROGRAM is not hung however because if I close the dialog then it will continue.
    Expected results:
    The JProccessBar should always move and the SwingWorker should always run the done() method.
    Additional info:
    java thread dump after freeze, taken with kill -s SIGQUIT <pid>
    2008-06-25 12:25:50
    Full thread dump IcedTea Client VM (1.7.0-b21 mixed mode):
    "DestroyJavaVM" prio=10 tid=0x938afc00 nid=0x1419 waiting on condition
    [0x00000000..0x0018a074]
       java.lang.Thread.State: RUNNABLE
    "AWT-EventQueue-0" prio=10 tid=0x938ae400 nid=0x1429 in Object.wait()
    [0x07f96000..0x07f96f04]
       java.lang.Thread.State: WAITING (on object monitor)
            at java.lang.Object.wait(Native Method)
            - waiting on <0x96748f80> (a java.awt.EventQueue)
            at java.lang.Object.wait(Object.java:503)
            at java.awt.EventQueue.getNextEvent(EventQueue.java:485)
            - locked <0x96748f80> (a java.awt.EventQueue)
            at
    java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:248)
            at
    java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:201)
            at
    java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:195)
            at java.awt.Dialog$1.run(Dialog.java:1073)
            at java.awt.Dialog$3.run(Dialog.java:1127)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.awt.Dialog.show(Dialog.java:1125)
            at java.awt.Component.show(Component.java:1456)
            at java.awt.Component.setVisible(Component.java:1408)
            at java.awt.Window.setVisible(Window.java:871)
            at java.awt.Dialog.setVisible(Dialog.java:1012)
            at net.xtel.production.WaitDialog.showWaitDialog(WaitDialog.java:72)
            at net.xtel.production.WaitDialog.showWaitDialog(WaitDialog.java:102)
            at TestClass2.showWait(TestClass2.java:79)
            at TestClass2.createAndShowGUI(TestClass2.java:126)
            at TestClass2.access$0(TestClass2.java:114)
            at TestClass2$3.run(TestClass2.java:138)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:227)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:603)
            at
    java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:276)
            at
    java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:201)
            at
    java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:191)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:139)
    "AWT-Shutdown" prio=10 tid=0x938ad000 nid=0x1428 in Object.wait()
    [0x03ea7000..0x03ea7f84]
       java.lang.Thread.State: WAITING (on object monitor)
            at java.lang.Object.wait(Native Method)
            - waiting on <0x96749268> (a java.lang.Object)
            at java.lang.Object.wait(Object.java:503)
            at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:281)
            - locked <0x96749268> (a java.lang.Object)
            at java.lang.Thread.run(Thread.java:675)
    "AWT-XAWT" daemon prio=10 tid=0x938a8400 nid=0x1423 runnable
    [0x02ccc000..0x02ccd104]
       java.lang.Thread.State: RUNNABLE
            at sun.awt.X11.XToolkit.waitForEvents(Native Method)
            at sun.awt.X11.XToolkit.run(XToolkit.java:550)
            at sun.awt.X11.XToolkit.run(XToolkit.java:525)
            at java.lang.Thread.run(Thread.java:675)
    "Java2D Disposer" daemon prio=10 tid=0x93854000 nid=0x1421 in Object.wait()
    [0x07aea000..0x07aead84]
       java.lang.Thread.State: WAITING (on object monitor)
            at java.lang.Object.wait(Native Method)
            - waiting on <0x966e7010> (a java.lang.ref.ReferenceQueue$Lock)
            at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)
            - locked <0x966e7010> (a java.lang.ref.ReferenceQueue$Lock)
            at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:150)
            at sun.java2d.Disposer.run(Disposer.java:143)
            at java.lang.Thread.run(Thread.java:675)
    "Low Memory Detector" daemon prio=10 tid=0x93c15000 nid=0x141f runnable
    [0x00000000..0x00000000]
       java.lang.Thread.State: RUNNABLE
    "CompilerThread0" daemon prio=10 tid=0x93c13400 nid=0x141e waiting on condition
    [0x00000000..0x03a8a954]
       java.lang.Thread.State: RUNNABLE
    "Signal Dispatcher" daemon prio=10 tid=0x93c11c00 nid=0x141d waiting on
    condition [0x00000000..0x00000000]
       java.lang.Thread.State: RUNNABLE
    "Finalizer" daemon prio=10 tid=0x095e7000 nid=0x141c in Object.wait()
    [0x005d2000..0x005d3004]
       java.lang.Thread.State: WAITING (on object monitor)
            at java.lang.Object.wait(Native Method)
            - waiting on <0x966e71d8> (a java.lang.ref.ReferenceQueue$Lock)
            at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)
            - locked <0x966e71d8> (a java.lang.ref.ReferenceQueue$Lock)
            at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:150)
            at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:177)
    "Reference Handler" daemon prio=10 tid=0x095e2400 nid=0x141b in Object.wait()
    [0x00581000..0x00582084]
       java.lang.Thread.State: WAITING (on object monitor)
            at java.lang.Object.wait(Native Method)
            - waiting on <0x966e7260> (a java.lang.ref.Reference$Lock)
            at java.lang.Object.wait(Object.java:503)
            at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:134)
            - locked <0x966e7260> (a java.lang.ref.Reference$Lock)
    "VM Thread" prio=10 tid=0x095dec00 nid=0x141a runnable
    "VM Periodic Task Thread" prio=10 tid=0x93c17400 nid=0x1420 waiting on condition
    JNI global references: 836
    Heap
    def new generation   total 960K, used 152K [0x93f40000, 0x94040000, 0x966a0000)
      eden space 896K,   9% used [0x93f40000, 0x93f56148, 0x94020000)
      from space 64K, 100% used [0x94020000, 0x94030000, 0x94030000)
      to   space 64K,   0% used [0x94030000, 0x94030000, 0x94040000)
    tenured generation   total 4096K, used 1088K [0x966a0000, 0x96aa0000, 0xb3f40000)
       the space 4096K,  26% used [0x966a0000, 0x967b01b0, 0x967b0200, 0x96aa0000)
    compacting perm gen  total 12288K, used 9169K [0xb3f40000, 0xb4b40000, 0xb7f40000)
       the space 12288K,  74% used [0xb3f40000, 0xb4834740, 0xb4834800, 0xb4b40000)
    No shared spaces configured.CLASS1:
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.sql.SQLException;
    import java.util.concurrent.ExecutionException;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.RepaintManager;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    public class TestClass2 extends JFrame implements ActionListener {
            /** Action Command for <code>searchbtn</code> */
            public static final String SEARCH_BTN_ACTION = "search_btn_action";
             * Constructor.
            public TestClass2() {
                    setSize(650, 350);
                    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                    setLocation(screenSize.width / 2 - getSize().width / 2,
                                    screenSize.height / 2 - getSize().height / 2);
                    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                    addWindowListener(new WindowAdapter() {
                            @Override
                            public void windowClosing(WindowEvent e) {
                                    exit();
                    JPanel panel = new JPanel();
                    add(panel);
                    setVisible(true);
            @Override
            public void actionPerformed(ActionEvent e) {
                    if (e.getActionCommand().equals(SEARCH_BTN_ACTION)) {
                            JOptionPane.showMessageDialog(this, "Button Pressed");
            public void showWait() {
                    try {
                            WaitDialog.showWaitDialog(this, "Testing...", new SwingWorkerInterface(){
                                    @Override
                                    public Object workToDo() throws Throwable {
                                            Thread.currentThread().sleep(3000);
                                            return null;
                    } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    } catch (ExecutionException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
             * Exits the program.
            public void exit(){
                    System.exit(0);
             * Create the GUI and show it. For thread safety, this method should be
             * invoked from the event-dispatching thread.
             * @throws UnsupportedLookAndFeelException
             * @throws IllegalAccessException
             * @throws InstantiationException
             * @throws ClassNotFoundException
             * @throws NullInstanceVariableException
             * @throws SQLException
            private static void createAndShowGUI() {
                    // set look and feel
                    try{
                            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                            // Create instance of the ProductCatalog
                            TestClass2 root = new TestClass2();
                            for(int i = 0; i < 10; i++){
                                    root.showWait();
                    }catch(Exception e){
                            e.printStackTrace();
             * @param args
             *            this program does not use arguments
            public static void main(String[] args) {
                    SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                    createAndShowGUI();
    }CLASS 2:
    import java.awt.Component;
    import java.awt.Frame;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.concurrent.ExecutionException;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.SwingWorker;
    public class WaitDialog extends JDialog {
            private boolean disposed = false;
            private boolean displayed = false;
            private WorkerThread worker = null;
            WaitDialog(Frame parent, String text, SwingWorkerInterface in){
                    super(parent, true);
                    worker = new WorkerThread(in);
                    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                    addWindowListener(new WindowAdapter() {
                            @Override
                            public void windowOpened(WindowEvent e) {
                                    worker.execute();
                            @Override
                            public void windowClosing(WindowEvent e) {
                                    disposeWaitDialog();
                    this.setResizable(false);
                    JLabel message = new JLabel();
                    message.setText(text);
                    JProgressBar pb = new JProgressBar();
                    pb.setIndeterminate(true);
                    // set size and location
                    setSize(200, 100);
                    setLocationRelativeTo(parent);
                    JPanel panel = new JPanel();
                    panel.add(message);
                    panel.add(pb);
                    add(panel);
            public void showWaitDialog(){
                    if(displayed == true){
                            return;
                    if(disposed == true){
                            disposed = false;
                            return;
                    disposed = false;
                    displayed = true;
                    setVisible(true);
            public void disposeWaitDialog(){
                    if(disposed == true){
                            return;
                    if(displayed == true){
                            displayed = false;
                            setVisible(false);
                            return;
                    disposed = true;
                    displayed = false;
            public static Object showWaitDialog(Component parent, String text, SwingWorkerInterface in) throws InterruptedException, ExecutionException {
                    WaitDialog waitDialog = null;
                    if (parent == null) {
                            waitDialog = new WaitDialog(JOptionPane.getRootFrame(), text, in);
                    } else {
                            waitDialog = new WaitDialog(JOptionPane.getFrameForComponent(parent), text, in);
                    while(!waitDialog.worker.isDone()){
                            System.out.println("about to show");
                            waitDialog.showWaitDialog();
                            System.out.println("done showing");
                    waitDialog.dispose();
                    return waitDialog.worker.get();
            class WorkerThread extends SwingWorker<Throwable, Void> {
                    private SwingWorkerInterface in = null;
                    WorkerThread(SwingWorkerInterface in){
                            this.in = in;
                    public Throwable doInBackground(){
                                    try {
                                            System.out.println("about to do work");
                                            in.workToDo();
                                            System.out.println("done work no exception");
                                    } catch (Throwable e) {
                                            System.out.println("done work with exception");
                                            return e;
                                    return null;
                    public void done(){
                                    System.out.println("about to dispose");
                                    disposeWaitDialog();
                                    System.out.println("disposed");
    }CLASS 3:
    public interface SwingWorkerInterface {
            public Object workToDo() throws Throwable;
    }

    There's nothing directly wrong with it, but it will
    prevent other threads acquiring the class lock - but
    that may be what you want.True. Although the typical case for code that looks like this would be to use wait--usually the various threads in question require the same lock, so you have to use wait in order for the waiting thread to give it up and allow the other thread to do its work. Hard to say for sure though what he's doing.
    Also, if loading is all that the other thread does, and you're waiting for that thread to die, use join. But then, if that's the case, and you're only waiting for a single other thread, then you might as well just put it all in one thread, as already indicated.

Maybe you are looking for

  • OutOfMemory-help on memory saving tips

    Hello, I am fairly new with Java. My software ran out of memory when I tried to process much more input than it had ever done before. I realized that one of the problems was that it woudl have been a good idea to specify the size of the big ArrayList

  • Vertical Photos Sideways In Finder

    I have a Canon PowerShot S5. The orientation of the camera is saved in the EXIF data, so any vertical photo imported is imported right-side up. (I use Image Capture to import the photos; I don't use iPhoto.) Vertical photos are vertical in Preview, a

  • Trouble with 10.3.9: possiblly network or permissions problems?

    Hello, I'm running OS X 10.3.9 on my iBook G3 (old but still works ) Lately I've had a problem with my entire interface that may be related to file paths, network problems or permissions problems. Whenever I try to open anything on my desktop (includ

  • Computer died !!!

    Have to upgrade computer as died so have to reinstall old programs onto Windows 8.1. Can I upload Ilustrator CS4, Lightroom 2 and lastly no new Photoshop as lost my CS2 so only have Photoshop 7 !!! Think the latter NOT possible !!! ?? Thanks Shona

  • I can't launch my apps after dowloading them

    I went the process of downloading extracting, but I'm not able to launch my apps