Disabling mouse events

hi,
I am having objects on a JFrame that respond to mouse events. I would like to know how I can disable these events. I use the addMouseListener to register a mouse event on something. Is there a way to remove or to deregister mouse events.
I basically have a game of tiles on a JFrame and I am going to have the human player play against the computer. I want to be able to have turns; computer and human player turn.

removeMouseListener()

Similar Messages

  • DISABLE MOUSE EVENT on jlabel

    Dear all,
    I have a jlabel on which i perform a click and the embbeded image switch between start and stop image.
    My problem consists in preventing from performing multiples click/or disabling mouse event while the application starts loading some parameters.
    switchViewLabel.addMouseListener(new MouseAdapter() {
                   public void mouseClicked(MouseEvent e) {
                        //it takes a long time
                                   onSwitchViewButtonClick();
    protected void onSwitchViewButtonClick() {
              System.out.println("onSwitchViewButtonClick");
              if (canGo) {
                   System.out.println("canGo");
                   canGo = false;
                   MainWindowPeer.getInstance().setCursorToWait();
                         //this action load parameter
                            CommandWindow.getInstance().switchView();
                         refreshSwitchViewButton();
                   MainWindowPeer.getInstance().setCursorToDefault();
                   canGo = true;
         } But on my console i have noticed :
    canGo
    onSwitchViewButtonClick
    canGo
    onSwitchViewButtonClick
    canGo.....
    It looks like we store mouse event anywhere and for each event we execute onSwitchViewButtonClick code and consume event.(it seems to not be asynchronous)....
    How to do ???
    Thanks for any helps..

    Dear all,
    yes i want to ignore mouse events until the processing is done.But how to perform process in separate thread and what is a semaphore.Is it possible to have much more explanation...
    Shall i do following code..
    mouseAdapter = new MouseAdapter() {
                   public void mouseClicked(MouseEvent e) {
                        SwingUtilities.invokeLater(new Runnable(){
                             public void run() {
                                  //switchViewLabel.removeMouseListener(mouseAdapter);
                                  onSwitchViewButtonClick();
                                  //switchViewLabel.addMouseListener(mouseAdapter);
              };Thanks you in advance...

  • Disable mouse events in ActiveX control

    Hi,
    I am using the Quicktime COM/ActiveX control for Windows from C# but want to change its default behaviour slightly.
    Currently when the mouse is pressed on the player control it pauses, resumes when double clicked or if already playing reverts to fullscreen mode.
    How can I disable this behaviour so that mouse clicks on the control do nothing?
    I can respond to mouse down events and intercept the message in WndProc but the control still seems to recieve the message before my application code.
    I get the feeling that I just need to change a property of the player, but which one?
    Thanks in advance for your help.
    James

    Mate, you are a total life saver!!!!!!!!!
    Thanks so much again.

  • Disable Mouse Events

    There is an area of the application I am working on in which one frame is calling another frame to open. The frame that is being called takes about 10 seconds to load. My problem is that while the frame is loading, I want to disable the user from clicking their mouse while this frame loads. I have read about glass panes, but was wondering if there was a way to just disable the mouse click.

    you could unistall the mouse handler for the object, or use a flag in the mouse handler that would be set for a wait condition, and thus, instructing the handler to process or pass through.

  • Disable JTree and stop it from receiving mouse events

    Hi,
    I have a JTree which has a mouse listener associated with (which is used for right-click operations)..,..anyway I am trying to disable the tree, so I call setEnabled(false)...which, as documented, disables the tree but it will still receive mouse events. I also tried, setEditable(false)..... the only way I can think of is to remove the mouse listener, and then when I want to re-enable the tree, I have to add it back.
    is there some other way?
    thanks

    Hi,
    I have a JTree which has a mouse listener
    ner associated with (which is used for right-click
    operations)..,..anyway I am trying to disable the
    tree, so I call setEnabled(false)...which, as
    documented, disables the tree but it will still
    receive mouse events. I also tried,
    setEditable(false)..... the only way I can think of
    is to remove the mouse listener, and then when I want
    to re-enable the tree, I have to add it back.
    is there some other way?Why do you want another way? This seems like a perfectly viable way to accomplish what you want.

  • Mouse Events on Disabled Buttons

    Hi,
    In my application I should make a disabled button to show a tool tip when mouse is entered onto it.
    I'm using java.awt.container not Jcontainer.
    I have searched in SDN forums and after reading some of the comments what I understood is �disabled Swing button can react to Mouse events but a disabled awt button can not react to mouse events�.
    Is that true or did I not understand correctly?
    And how would I be able to implement the required functionality in my
    application?
    Thanks.

    import java.awt.*;
    import java.awt.event.*;
    public class AwtTooltip {
        private Panel getContent(Frame f) {
            Button left = new Button("left");
            left.setEnabled(false);
            Button right = new Button("right");
            Panel panel = new Panel(new GridBagLayout());
            new TipManager(panel, f);
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            panel.add(left, gbc);
            panel.add(right, gbc);
            return panel;
        public static void main(String[] args) {
            AwtTooltip test = new AwtTooltip();
            Frame f = new Frame();
            f.addWindowListener(closer);
            f.add(test.getContent(f));
            f.setSize(300,100);
            f.setLocation(200,200);
            f.setVisible(true);
        private static WindowListener closer = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
    class TipManager extends MouseMotionAdapter {
        Panel component;
        Window tooltip;
        Label label;
        public TipManager(Panel panel, Frame frame) {
            component = panel;
            panel.addMouseMotionListener(this);
            initTooltip(frame);
         * Since enabled Buttons consume MouseEvents we will
         * receive events sent only from disabled Buttons.
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            boolean hovering = false;
            Component[] c = component.getComponents();
            for(int j = 0; j < c.length; j++) {
                Rectangle r = c[j].getBounds();
                if(r.contains(p)) {
                    hovering = true;
                    if(!tooltip.isShowing())
                        showTooltip(c[j], p);
                    break;
            if(!hovering && tooltip.isShowing()) {
                tooltip.setVisible(false);
        private void showTooltip(Component c, Point p) {
            String text = ((Button)c).getLabel();
            label.setText(text);
            tooltip.pack();
            convertPointToScreen(p, component);
            tooltip.setLocation(p.x+10, p.y-15);
            tooltip.setVisible(true);
        /** Copied from SwingUtilities source code. */
        public void convertPointToScreen(Point p, Component c) {
            Rectangle b;
            int x,y;
            do {
                if(c instanceof Window) {
                    try {
                        Point pp = c.getLocationOnScreen();
                        x = pp.x;
                        y = pp.y;
                    } catch (IllegalComponentStateException icse) {
                        x = c.getX();
                        y = c.getY();
                } else {
                    x = c.getX();
                    y = c.getY();
                p.x += x;
                p.y += y;
                if(c instanceof Window)
                    break;
                c = c.getParent();
            } while(c != null);
        private void initTooltip(Frame owner) {
            label = new Label();
            label.setBackground(new Color(184,207,229));
            tooltip = new Window(owner);
            tooltip.add(label);
    }

  • How can i disable mouse right clicking event

    I need in my project to disallow any body to right click the mouse. Can i disable this event to prevent user of the application from right clicking if yes how can i disable it.

    I have code written in Visual Basic doing the same task but i don't know how to transfer those code in java
    The following is a code for that:
    Option Explicit
    'declares
    Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
    'constant
    Private Const WH_MOUSE_LL = 14&
    Public Const HC_ACTION = 0&
    Public Const WM_RBUTTONDOWN = &H204
    Public Const WM_RBUTTONUP = &H205
    Public Const VK_RBUTTON = &H2
    Private lMShook As Long
    Private bHookEnabled As Boolean
    'functions which process mouse events
    Public Function MouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If nCode = HC_ACTION Then
    If (wParam = WM_RBUTTONUP Or wParam = WM_RBUTTONDOWN) Then
    MouseProc = 1
    Exit Function
    End If
    End If
    MouseProc = CallNextHookEx(lMShook, nCode, wParam, lParam)
    End Function
    Public Function SetHook()
    If lMShook = 0 Then
    lMShook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, 0&)
    End If
    If lMShook = 0 Then
    MsgBox "failed to install hook :" & lMShook & " : " & WH_MOUSE_LL
    bHookEnabled = False
    Unload Form1
    Exit Function
    Else
    bHookEnabled = True
    End If
    End Function
    Public Function UnSetHook()
    If bHookEnabled Then
    Call UnhookWindowsHookEx(lMShook)
    lMShook = 0
    End If
    bHookEnabled = False
    End Function
    Public Function InstalledHook()
    MsgBox " installed hook is :" & lMShook
    End Function
    code for form is below:
    Option Explicit
    Private Sub Command1_Click()
    InstalledHook
    End Sub
    Private Sub Command2_Click()
    Call SetHook
    End Sub
    Private Sub Command3_Click()
    Call UnSetHook
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
    Call UnSetHook
    End Sub

  • How can I disable any mouse event while is another is processing?

    Hi!
    I've a problem and I need some help.
    I'm downloading an image in the MouseAdapter's mouseClicked method. So I need to disable any other mouse events produced durring this download. These events can be removed from the queue or is there is any way to disable entering mouse events to the queue while another one is processing?
    If anyone can halp me, thanks a lot.

    Interesting situation. I would suggest that the downloading be done on another thread; long processes shouldn't be handled on the swing thread in most situations. Then to stop the mouse events you'd simply disable the component that has the mouse listener until the image has finished loading. That way these events will be processed and discarded while the image is loading.
    ie,
    public void mouseClicked(MouseEvent e)
      final Component source =  (Component)e.getSource;
      source.setEnabled(false); //stop further mouse events.
      new Thread()
          public void run()
             loadImage(); //should not return until image is loaded
             source.setEnabled(true);
    }Hope that helps. :)

  • Firefox mouse event not behaving the same on PC and Mac computers

    I use the FCKEditor and having a very strange problem. When I click on the FCKEditor's editing area, the keyboard gets disabled untill I click the mouse somewhere outside of the editing window. The problem only happen on Firefox (3.6.10) on Mac computer (Snowleopard 10.6.4). Doing exactly the same steps on PC works without any problem.
    What I want to know:
    - Is it possible that the Firefox on Mac is different than the PC in handling mouse events? Or some other areas?

    Sounds more that Firefox is treating that editor area as read-only.
    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]

  • Touch to Mouse events conversion

    Hi Everybody!
    Does anybody know how correctly fire mouse events to Oracle Maps in javascript?
    Default translation touch events in iPad Safari does not quite fit. It try zoom or pan browser window, not map. :(
    If catch touch events and disable default translation I can zoom and pan MVMapView object.
    But how fire "click","mousemove","mouseover" events on Map? I need dispatch event to ThemeBasedFOIs (InfoWindow Popup and other listeners)?

    Yes. The Oracle Maps tutorial contains examples (the tutorial can be found in your mapviewer deployment
    e.g. http://localhost:7001/mapviewer/fsmc/tutorial/index.html) and documentation in the API reference
    (e.g. http://localhost:7001/mapviewer/fsmc/apidoc/index.html). Look at MVEvent and the attachEventListener function of MVMapView, MVThemeBasedFOI, and MVFOI classes for example.

  • Inappropriate mouse event coordinates in the WebKit of HTMLLoader/StageWebView

    Hi,
    We have a desktp application which incorporates an HTMLRichTextEditor (implemented in HTML/JS and loaded into AIR).
    We have run into a big problem with text selection though. It seems that the both the HTMLLoader and the StageWebView are passing wrong mouse coordinates to the WebKit when the cursor is outside of the component.
    I've created a sample application which uses mx:HTML (which is a wrapper of the HTMLLoader) and a WebView class (a wrapper aroun StageWebView reference to which is given here).
    The application is located here in Dropbox. The source code of the app is here.
    The app was built with Flex 4.6 and ran in AIR 3.7
    The sample app has a WebView which loads loremipsum and HTML loading some dummy local HTML page. The HTML page uses the JS->AIR bridge to report the mouseevents to a function in AIR. In the snapshot below the selection was started from the first row and then slowly continued to the left. As soon as it reaches the green area the selection changes unexpectably. As it can be seen in the bottom right -> the WebKit has received a mouse event with incorrect coordinates. The reported mouse coordinates seem to be the mouse coordinates within the green component and the selection behaves like that. If the mouse is moved to the blue - the selection changes again (according to the coordinates in the blue area).
    The component which uses the StageWebView behaves in absolutely the same way.
    I'd assume that I have to post a bug but I decided to post here at first.
    I've tried a few workarounds in order to stop and ongoing selection or to change it's behaviour but none of them with any relevant success. Even disabling mouse children for the entire application has no effect on the selection once it's started.
    Any help and/or comments would be much appreciated.
    Thanks !

    Thank you for the heads up.  Do you know if this is a recent change in behavior with AIR (ie. does this occur in previous versions)?  Regardless, could you please open a new bug report on this over at bugbase.adobe.com? 
    Once added, please post back with the URL so that others affected can add their comments and votes and I can follow up internally.
     

  • Absorbing mouse events

    In my application, if someone clicks on a button about 10 times before it visually updates itself, the first click, initializes a change in the GUI, and another button appears in the same place. The second click, is then processed after the first press has completed, and calls the action on the next button, and so on and so on. I want to be able to stop it from doing this. Since it is all on the same thread, I can't say, absorb all button clicks until this event is complete, because they are all still sitting in the event queue. I don't exactly have a whole lot of useful methods to use in the EventQueue class to just say, hey remove all mouse events at this point. Any Ideas?
    Maybe this will describe the situation better.
    Mouse Click #1 added to queue
    Mouse Click #1 removed from queue, processing event.
    Mouse Click #2 added to Queue
    Mouse Click #3 added to Queue
    Mouse Click #4 added to Queue
    Mouse Click #5 added to Queue
    Mouse Click #1 completed event, new screen is visible.
    Mouse Click #2 removed from queue, processing event on button on new screen.
    ...and so on
    I want to be able to ignore all mouse events prior to Mouse Click #1's completion.

    Suppose that when you start processing a mouse event
    you set a busy flag somewhere, and when you finish
    processing it you reset the flag. Your mouse listener
    checks the busy flag and drops the click event if it's
    set.Problem with this is when I'm at the end of the process, then I enabled the flag, THEN the next event gets processed, and the flag is enabled.
    As far as disabling and enabling the buttons, I can try it, but I'm betting it is falling into the same scenario as the flag. My big issue is people double clicking, and the clicks are all registering as 1 click, so 2 seperate events get fired, first one changes the screen, second one clicks on the button on the next screen.
    I may have some across a solution that I will test later. It involves storing the completion time of the operation, then when starting the next event, check the event time and see if it is after the completion time, otherwise return.

  • Disabling further events until subVI closes

    Hi All.
    I'm having an issue regarding mouse down events that continuing to register altough another control is on top.
    As can be seen in 1.vi attached
    when I press the control "1" , subvi 2.vi opens, but if i continue to mouse down the control (on the same place) and then closing 2.vi I get that that 2.vo pops up again
    It's like the String doesn't cover the 1 and 2 controls.
    after pressing 1 or 2 and 2.vi pops I would like to disable further events until I stop 2.vi execution
    Modal is not an option for me sue to graphics issues
    I have also tried to "cover" 1 and 2 control with boolean but witout success.
    Any ideas?
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    1.vi ‏16 KB
    2.vi ‏7 KB

    KJmaster wrote:
    I can't use modal because when u run a modal window it gets a 3d frame unlike float window who has a flat look.
    I'm not seeing this at all.  What settings were you using?  Can you post a screenshot?
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Disable Mouse Listener

    How can I temporarily disable then reenable the mouse listener? Users click on the screen to designate coordinates for a shape to be drawn on. However, when the user selects a shape in a JComboBox, coordinates are being set near the JComboBox near where they clicked on their shape selection. I don't want the mouse listener event to fire when they're making a selection in a JComboBox or even typing something in a text box. Can anyone help me?

    What I've done before is to wrap the mouse listener with a boolean like this:
    foo.addMouseListener(new MouseAdapter (){
        public void mouseClicked(MouseEvent e){
            if(allowMouseEvents){
                doSomething();
    });Then, in the comboBox I do something like this:
    myComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            allowMouseEvents = false;
            doComboBoxSelectionActions();
            allowMouseEvents = true;
    });This turns off the mouse events during the time that I'm processing the combo box selections.
    Hope it helps

  • [SOLVED] Disabling Mouse Acceleration / Mouse unresponsive

    Hi,
    I play CSGO and need my mouse to be responsive with no mouse acceleration. Everything works find under Ubuntu 15.04 using the old xinput method of disabling mouse acceleration. However under Arch my mouse is really sensitive and unresponsive when making very small movements at slow speed (moving slightly to get a headsot at range in CSGO requires some presision)
    I've read the wiki page a coule of times and tried two different configs. Looking at diffs of my Xorg log the configs are getting picked up but seems to do very little. There doesnt appear to be any errors in Xorg log.
    I installed the full Xorg group am I missing a component of Xorg or a mouse driver?
    My Mouse is Gigabyte M6900
    http://www.gigabyte.com/products/produc … id=3616#ov
    Name           : xorg-server
    Version        : 1.17.1-5
    uname -a
    Linux desktop 4.0.4-1-ARCH #1 SMP PREEMPT Mon May 18 06:43:19 CEST 2015 x86_64 GNU/Linux
    First mouse accelleration config file as described in the wiki
    /etc/X11/xorg.conf.d/50-mouse-acceleration.conf
    Section "InputClass"
    Identifier "Areson USB Device"
    MatchIsPointer "yes"
    Option "AccelerationProfile" "-1"
    Option "AccelerationScheme" "none"
    EndSection
    The very first example of the wiki shows some settings for disabling mouse accelleration but still no joy
    Section "InputClass"
    Identifier "Areson USB Device"
    MatchIsPointer "yes"
    Option "AccelerationProfile" "-1"
    Option "AccelerationScheme" "none"
    Option "AccelerationNumerator" "1"
    Option "AccelerationDenominator" "1"
    Option "AccelerationThreshold" "0"
    EndSection
    A Diff of these Xorg log between the two config files
    < [ ] (==) Log file: "/var/log/Xorg.0.log", Time: Fri May 22 15:53:29 2015
    > [ ] (==) Log file: "/var/log/Xorg.0.log", Time: Fri May 22 17:45:05 2015
    346,347c346,350
    < [ ] (**) Areson USB Device: (accel) acceleration factor: 2.000
    < [ ] (**) Areson USB Device: (accel) acceleration threshold: 4
    > [ ] (**) Option "AccelerationNumerator" "1"
    > [ ] (**) Option "AccelerationDenominator" "1"
    > [ ] (**) Option "AccelerationThreshold" "0"
    > [ ] (**) Areson USB Device: (accel) acceleration factor: 1.000
    > [ ] (**) Areson USB Device: (accel) acceleration threshold: 0
    egrep -i 'error|fail|firmware' /var/log/Xorg.0.log
    (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
    [ 112.912] (WW) Open ACPI failed (/var/run/acpid.socket) (No such file or directory)
    [ 114.973] (II) NVIDIA(0): ACPI: failed to connect to the ACPI event daemon; the daemon
    Last edited by fixles (2015-05-22 20:34:45)

    brebs wrote: Here is the libinput bug report re acceleration - it ain't fully disabling acceleration.
    So it doesnt work but its not broken? lol
    as for AccelSpeed -1, you're correct that it currently does some deceleration below the threshold. having said that, the pointer accel code isn't finished yet either, e.g. it doesn't do any constant deceleration, so the -1 setting is a bit off anyway.
    I can't promise you a timeline or whether this will get fixed in the way you want it to. we're trying to simplify a couple of things, pointer acceleration is one of those, and that means that not every configuration that was previously possible will be possible in the future.
    Followed up by a pretty funny response.
    Honestly that sounds a bit like "we know what you want better than you know what you want". libinput isn't secretly a Gnome project is it?

Maybe you are looking for

  • Probably caused by : ntoskrnl.exe ( nt+72f40 )

    Dear Friend, I have a windows server 2008R2 running on Hyper v .The host machine is running windows server2012.on this server,Exchange application is running.This server is getting rebooted itself on every 15-20 days.the mini blue dumb for the issue

  • Help please , screen problem  with my 2GB ipod nano

    Hello guys A month ago i had to change the battery for my ipod , after that eveything worked fine for awhile then the screen was half blank and half i can see the menu, so i thought its a problem with the screen to i odered another one , and when i i

  • XSL-1009 error in XML to XML using XSL

    I'm using XSL to transform one XML format to another using and XSL transform file. I'm initiating this with ORAXSL in.xml transform.xsl out.xml. The XSL file has in it: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.oracle.com/XSL/Transf

  • Can't use "pinch open & close" in iPhoto

    Hi! My problem is not serious, but it's really annoying. I'm used to using "pinch open & close" in iPhoto but now I can't do it. When I try to zoom my picture with it, the whole window of the application disappeared. I can zoom my picture only using

  • Process Flow - ordering of mappings

    hello group, i've developed a simple process flow which loads several mappings in a sequence. it has to be stated that mapping A has to be loaded before mapping B. when i am running this process flow i get a litte bit confused. in the job details map