Double click detection

Hello,
I have a JTree and I want to detect mouse double click over some nodes. I am using the following code in my JTree (which implements MouseListener) :
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2)          
// MY ACTION
the snag is that it also detect double clicks when it does not occured over a node. In that case I would like no action to be launched.
How can I do it ??
Thank you.
Sylvain.

Hi,
I achived the following way to get the things working like you would to. Take a look:
public void mouseClicked(MouseEvent evt) {
  if ( evt.getClickCount() == 2 ) {
   TreeNode node = (TreeNode)ree.getLastSelectedPathComponent();
   if ( node.isLeaf() ) {
    // Go ahead
I hope this help you.
Regards,
Ualter Junior.

Similar Messages

  • Incorrect detection of double-clicks in layers and channels windows. (Mac OS X 10.6.8)

    Photoshop will detect a double-click in the layers and channels panels even when there are different modifier keys held down on the first click vs. the second click.
    I have never intended to double-click and accidentally changed the modifiers I was holding down between clicks.  I often perform an action requiring modifier keys and immediately follow it with an action that requires no modifiers (or different modifiers).
    I realize that the conventions for what constitutes a double-click are platform dependent and not particularly well documented, but I do expect Photoshop to work the way that my operating system does (Mac OS X 10.6.8)).  I know older versions of Windows detected double-clicks even when modifiers were changed between clicks, but I believe the latest versions behave similarly to OS X.
    Examples:
    Start by having a document open with multiple alpha channels and layers in it.
    Select an alpha channel by clicking on it's thumbnail in the channels panel.
    Quickly hold down the control key and click again.
    Result: this brings up the "Channel Options" window. (as if you had double-clicked)
    Expected result: should bring up the channel's contextual menu.
    Bonus extra nitpick:  The window opened on mouse-down, not on mouse-up.
    Create a non-blank alpha channel.
    Hold down the command key and click on that alpha channel's thumbnail. (loads the channel into the selection)
    Quickly release the command key and press the mouse button.
    Result: Brings up the "Channel Options" window. (as if you had double-clicked)
    Expected result: Start a drag operation on the channel.
    Click on a layer in the layers panel to select it.
    Move the mouse pointer to a different layer.
    Hold down the shift key and click to select multiple layers.
    Quickly release the shift key and press the mouse button.
    Result: Brings up the "Layer Style" window.  (as if you had double-clicked)
    Expected result: Begin a drag operation.
    Bonus extra nitpick:  The window opened on mouse-down, not on mouse-up.
    Interestingly the layers panel does the correct thing when control is pressed between clicks, but the channels panel does not.
    The options windows opening on mouse-down instead of mouse-up has never bothered me, but I believe it goes against convention.
    Thanks.

    Very detailed report, Jay. I was able to see exactly what you're talking about, and reproduce this using my trackpad. I'm wondering if this is an OS issue, or something that can be tweaked in Photoshop. Even with files in Finder, you can activate a double-click even with a slight hesitation, which is similar to the behavior in Photoshop.

  • Slow Start-Up / Slow Detection to double click

    Hi,
    My ibook has been ok until my friend installed a 1 GB fonts into my com, and this resulted in a slow start up to my ibook, even though ive already uninstalled it.
    Secondly, the com also seems to be slower in detecting double clicking.
    Anyone can solve the problem???
    Angela An

    Hi, Angela. Welcome to Apple Discussions.
    Have you tried resetting the PMU?

  • JTable - detecting double click

    i'm trying to detect double click on a row in a JTable and then find out the row number. i can get it to detect the double click with the table disabled but the row always comes back as -1. if i try setEnabled(false) it doesn't detect the double click at all.

    I think your table should be enabled. Put a mouse listener on the table like:
    myJTable.addMouseListener(new ClickMouseListener());
    class ClickMouseListener extends MouseAdapter
        public void mouseClicked(MouseEvent e)
          if (e.getClickCount() == 2)
            Point pt = e.getPoint();
            int row = myJTable.rowAtPoint(pt);
            System.out.println("Mouse clicked on row " + row);
    }If you also have selection enabled then the row will also be the selected one so that would be another way of determiing the row number.

  • Detect a double click event

    Hi,
    In my plugin , I'd like to detect a double click event in an annotation.
    I've already found how to detect a single click by using avPageViewClickProc and AVPageViewIsAnnotAtPoint but I don't know how to proceed for a double click.
    Thanks in advance...

    your click proc gets the number of clicks, IIRC.
    Leonard

  • Detecting single and double click on row click

    Hello All,
    I am using jdev 11.1.1.6
    I have a table displayed like below,
                                     <af:table value="#{pageFlowScope.Bean.List}" var="temp"
                                      rows="1500" rowBandingInterval="0" >                                  
                                          <af:column id="dc_c1" align="center" clientComponent="true" headerText="Heade1" >
                                           <af:outputText value="#{temp.value1}" escape="false"
                                                          id="dc_ot1"/>
                                          </af:column>
                                      </af:table>
    I want to detect
    - single click on a row
    - double click on a row
    How can i achieve it ?

    Hi,
    You need the combination of a client listener, a Javascript function and a server listener.
    Frank Nimphius has provided a comprehensive example here.
    Kevin

  • Detecting double-click in the action of a JButton

    I have a similar problem to the poster of http://forum.java.sun.com/thread.jsp?forum=52&thread=93004 and I'm wondering if anyone has a better solution.
    A fuller description of my problem.
    My JButtons represents certain pallette items. Clicking a pallete item puts the button in a selected state (changes its border to show it's selected). The action on this button sets a mode state on the canvas to indicate what was selected. I then click on a canvas workspace to place an instance of that item onto the canvas based on the current mode.
    The selected JButton then pops up and the user needs to select a new pallette icon.
    What I want as an option so that if a pallette button is double-clicked it remains selected even after the item has been placed on the canvas allowing the user to place several copies around the canvas before selecting another item.
    I'd like if possible to determine this from the buttons action rather than registering a listener to the button because parts of the framework I am using pass just the actions around.
    I could do this by looking at the time between actions being triggered but this seems like a messy solution (can I pickup the operating system settings for double-click delay).
    Any other ideas?

    thebobster,
    This doesn't answer your original question, so if you're determined to use d-clicks on a JButton, don't bother reading further.
    I've always found double-clicking on a JButton non-intuitive, not to mention messy to implement. I prefer CTRL-click, etc, to indicate a sticky click.
    Perhaps you could use an image to indicate your palette button: you'll need just 2 images--up-state and down-state--and d-clicks will be easy to implement.
    --A                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to detect only single click and not double-click mouse events in Swing?

    Hi,
    In my application, I want to implement a functionality only for single click. But problem is on double click, first i can see a single click and then double click.
    i.e e.getCount() return 1 and then 2 for double click. I want to avoid this situation.
    Shouldn't it be just one event with a clickCount of 2? or any alternative solution?
    Please let me know how can i stop this.
    Thanks in advance..
    Cheers
    Somasekhar
    Edited by: SomasekharPatil on Mar 13, 2009 3:36 PM

    Maybe something like the below example:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.SwingUtilities;
    import javax.swing.Timer;
    public class SingleClickOnly {
        public static void main(String[] args) {
         SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
              new SingleClickOnly().createGUI();
        public void createGUI() {
         JFrame frame = new JFrame();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         JLabel label = new JLabel("Only acts on a single click");
         label.addMouseListener(createListener());
         frame.add(label);
         frame.pack();
         frame.setLocationRelativeTo(null);
         frame.setVisible(true);
        public MouseListener createListener() {
         return new MouseAdapter() {
             private int clickCount = 0;
             private final Timer timer = new Timer(1000, new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  if (clickCount == 1) {
                   System.out
                        .println("Executing action on click count 1 only");
              timer.setRepeats(false);
             @Override
             public void mouseClicked(MouseEvent event) {
              clickCount = event.getClickCount();
              System.out.println("Clicked: " + clickCount);
              if (clickCount == 1) {
                  if (timer.isRunning()) {
                   timer.stop();
                  timer.start();
    }Piet

  • A better way to Double Click

    I have been wondering if there is a better way to detect single clicks Vs double clikcs than the model currently implemented. I am sure all of you have run into the problem of even though an event listener detects a double click eventually, it detects the single click first, so often you have to compromise the quality of your software to account for that. I have considered writing my own custom handler using threads and such, but it seems to me there must be a better way out there that I just have not been able to find. I need a way to detect double clicks, and fool the machine into believing no single click has occured. Must I re-invent the wheel?
    AC

    I agree that GUIs should have some uniformity to
    them..especially as we enter an age where computers
    are ubiquitous. But there are some situations where
    customized behavior is preferrable. If you have ever
    worked with movie special effects software, some art
    software, music software, especially, you know that to
    make a GUI intuitive, sometimes liberties must be
    taken with the 'standard' gui design.The application determines the standard not the OS nor the GUI.
    And to say 'Your code is not standard, therefore the
    fact that java cannont accurately distinguish between
    single and double clicks is your problem' smacks of
    nonsense to me.
    We all know that Java is a great
    language.Java is not just a language it is a platform and a philosophy.
    It is quicker and easier to program in,
    than c++, but it is not at full maturity. Every c++
    development environment I have ever used had the
    ability built in to distinguish between a true single
    click and a double click.As does Swing..
    I love Java, but most
    programmers could fill a page with the enhancements
    that it needs. Not all enhancements are practical.
    Like many I balked when I first started with Java at
    the fact that it did not have true multiple
    inheritence. I now realize that
    I never really needed it anyway. But some things, eg
    templates, I definitely could still use. That being,
    said, thanks for the dialog. Templates are a complicated horror, unless you really need your software to be truly adaptable you will never use them. Even MS, Sun and IBM disposed of that need a long time ago.

  • RH7 HTML - Receive IE script error message when double-clicking link to auto-size pop-up

    Hi, all,
    Anybody ever seen this situation? When double-clicking on a link to an auto-size pop-up, I get the following Internet Explorer script error message:
    This error also occurs when I double-click the link in preview mode within the project. A colleague that is running the same version of IE with the same settings is not receiving this error. A couple of other co-workers are running a different version of IE, and one gets this error and one does not.
    This error does not occur if you single-click the link (which you would normally do), nor does it occur if you double-click a link to a fixed-size pop-up. Once you receive this message and click Yes or No, the link sometimes works correctly when you double-click. I haven't been able to establish a pattern. Also, if you single click the link to display the pop-up, click off of it, and then double-click the link, the error does not occur.
    As you can tell by now, this problem is kind of hard to pin down. I've done some research and I have yet to stumble upon anything that deals with this issue. Unless there is a solution out there, I can do one of two things: 1) change all of the auto-size pop-ups in the project to fixed-sized, which defeats the purpose of creating auto-size pop-ups, or 2) tell our customer not to double-click links.
    Any advice you could give would be welcome.

    Hi there
    Indeed it has been reported on many occasions over the years. Unless someone like Willam has some way cool error detection magick with the scripts, the best approach we have always offered is this.
    Educate your users on the way computers and HTML works. HTML works using SINGLE clicks, not DOUBLE clicks.
    The reason for the error is because the first click caused the computer to launch a JavaScript command to open the sized popup. The second click that followed in rapid succession confused things by asking the script to stop what it was doing and run again.
    Maybe it would help to explain it to your users like this. If you visited a restaurant and when the server asked what you wanted to order, would the become confused if you said to them: I'll have the T-Bone Steak and nearly immediately you repeated it by saying again I'll have the T-Bone Steak.
    Cheers... Rick
    Helpful and Handy Links
    RoboHelp Wish Form/Bug Reporting Form
    Begin learning RoboHelp HTML 7 or 8 within the day - $24.95!
    Adobe Certified RoboHelp HTML Training
    SorcerStone Blog
    RoboHelp eBooks

  • Double Click Mouse Events

    Hi,
    I have a JTable which I'm displaying to a set of users. There is a specific function that I want to perform if a user double clicks on any row. However I can't seem to find a way of doing this.
    The MouseListener interface only seems to produce events based on single clicks, but I specifically want a double click to generate the required function.
    Any ideas ?

    No, it doesn't always - although it is supposed to. I always get two single click events when I should get one double-click. I need to detect the double clicks for specific functionality also. I'm wondering if there is a "click-interval" I can set somewhere.
    I'm running jdk 1.2.1_04 on Solaris 8. Upgrading to 1.3 or better is not an option at the moment.

  • Files not opening on double click (Gnome)

    That is the problem im having.
    Im using a virtual Arch (virtualbox) via RDP ... all the system is fine. The only thing not working is that whenever i double click on any document//picture/archive it does not open it's default app....
    I dont think is something to do with the RDP protocol because if i open the mouse settings manager, where you have a small zone for testing the double click actions (the small bulb that lights on/off when you double click) the test shows that the system is actually detecting a double mouse click.............. is there any global settings, in gconf-editor, perhaps, where i can correct this?
    thank you!

    Solved: I had nautilus-elementary from archlinux.fr
    I did: pacman -Rd nautilus-elementary
    then:
    pacman -S nautilus
    All working again....

  • Double clicking brings up selection box rather than highlighting words

    This is a bit of a trivial problem but it's making my editing quite difficult. I'm using Acrobat X 10, with Windows 7.
    Normally when I double click on some text, the word that I am double clicking on will become highlighted. This continues to be the case except for in one specific pdf document: now double clicking opens a selection box rather than highlighting text. If I single click I can highlight whatever text I want, but double clicking no longer highlight a particular word. This is very incumbersome for my annotating/highlighting technique. It only happens with this one pdf, any other pdf and the selection tool is back to normal.
    Any idea why this is happening for this one particular pdf, but none of the others, or any way that I can make it highlight words via double clicking again?
    Edit: On further inspection, the problem seems to be that for this particular document, acrobat reader cannot detect specifc words, only individual characters. When I highlight a sentence, normally the text highlighted would naturally jump to the end of the word, but here it will only start/stop where I begin and end dragging the cursor. I have used the Recognise Text tool, but this did not fix the problem as it said it had already recognised the text throughout the document.             

    Can you use the "Prompt" section of the Property Palette instead and leave Label as null. Prompts can be aligned to the left, but, without trying it in Forms 4.5, am unsure about your highlight issue.

  • Gnome 3.16 & Wayland: double-click no worky and no desktop icons/menu

    I understand Wayland and Gnome are getting closer to "finished", and indeed my laptop's touchpad (HP Folio 13) now detects taps as primary mouse clicks, which is a marked improvement over 3.14, where taps weren't detected at all. Couple of issues stop it being "daily use" for me at present however:
    1) Despite "Test your settings" correctly showing "double-click primary button", the double-click isn't working as it should in Nautilus/Files i.e. double clicking or double tapping on a folder icon fails to open said folder. Interestingly double-click to drag *does* work, so I'm suspecting a Nautilus problem. NB double click with a proper mouse also doesn't work, so it's not a trackpad problem per se.
    2) Second problem is that my desktop icons (Home and a couple of folders) aren't showing up, despite using gnome-tweak-tool to set the desktop icons "On". And when I right-click on the gnome-wayland desktop the context menu only shows "Change Desktop Background" and "Settings...".
    Both of these probems aren't present on Gnome under X.
    Last edited by sultanoswing (2015-05-20 19:58:33)

    I can confirm both of these on my own Gnome 3.16 desktop as well. The no desktop icons I believe is a known thing with Gnome on Wayland (it doesn't exist, just like restarting Gnome Shell with Alt+F2 and r does not exist under Wayland either). The first issue I have never seen anywhere, and it does not seem limited to touchpads (hook up a mouse and you will see the same thing). Anyone experienced the lack of double click for folders in Nautilus/Files under Wayland? Any solutions?

  • Click Double click

    Hi there,
    Just a little question about java. I want to make call a method x when i click on my row and when i do a double click i want to call an different method as y
    I ve found this on the web :
    if (e.getClickCount() == 2)
    System.out.println( "-- and it's a double click!");
    else
    System.out.println( " and it's a simple click!");
    But with this part of code when i double click the simpleclick is also called. Is there another tips to detect a double click ?
    Regards

    Here is some code, it could be made more robust (synchronization, upgraded to 1.5, ...)
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    import javax.swing.Timer;
    public class MouseClicked implements MouseListener, ActionListener
         private MouseListener objListener;
         private MouseEvent objEvent;
         private Timer objTimer;
         private boolean bStop;
         public MouseClicked(MouseListener argListener)
              objListener = argListener;
              objEvent = null;
              objTimer = new Timer(100, this);
              bStop = false;
         public void actionPerformed(ActionEvent argEvent)
              if (bStop) {
                   objTimer.stop();
                   objListener.mouseClicked(objEvent);
                   objEvent = null;
              } else {
                   bStop = true;
         public void mouseClicked(MouseEvent argEvent)
              if (objEvent == null) {
                   objEvent = argEvent;
              } else {
                   if (objEvent.getComponent() == argEvent.getComponent()) {
                        if (objEvent.getClickCount() < argEvent.getClickCount()) {
                             objEvent = argEvent;
                        } else {
                             objEvent = new MouseEvent(argEvent.getComponent(), argEvent.getID(), argEvent.getWhen(), argEvent.getModifiers(), argEvent.getX(), argEvent.getY(), argEvent.getClickCount() + objEvent.getClickCount(), argEvent.isPopupTrigger());
                   } else {
                        objListener.mouseClicked(objEvent);
                        objEvent = argEvent;
              bStop = false;
              objTimer.restart();
         public void mouseEntered(MouseEvent argEvent)
         public void mouseExited(MouseEvent argEvent)
         public void mousePressed(MouseEvent argEvent)
         public void mouseReleased(MouseEvent argEvent)
    DeltaCoder

Maybe you are looking for

  • How to populate form bean (Action form) from Action  (Struts)

    Hello to all.. I have a problem populating a from bean in struts from Action class... What I would like is .. 1. how can I populate a formbean from Action so when a page (JSP) with tags will be displayed some tags will be set and some no (depends on

  • Error compiling "Undefined symbols for architecture armv6:"

    Hey, I seem to be getting errors like this a lot... I only just started making apps yesterday, so they are all still very basic, but I was wondering if I am doing something wrong when I import frameworks? This may be caused from something else entire

  • Problem Monitor Port stops working

    I set up a customer and put in a SPAN port on the switch and hooked it in as it should so that we can use the NTOP program.  After 10 - 15 min it stops getting data.  We reboot the onplus device and it starts working again for 10 min and again will s

  • Bank Holiday Blues - Access package in root directory..

    I have the following file directory: mainDir: ---- *PRESCRIPT (PACKAGE) ---- main.java (imports prescript & imports operators) ---- operators (package)      |      ----> *PRESCRIPT (PACKAGE)      |      ----> opertorA (imports prescript)      |      

  • About Flex SDK3

    1. Coldfusion 8: Flex Compiler Show: Project is being compiled with Flex 3.0, but server has Flex 2.0.1 How to make Flex 2.0.1 upgrade to Flex 3.0 of coldfusion gateway? modify file " wwwroot\WEB-INF\flex\services-config.xml"? 2. Why compiled SWF doc