How to handle both single click and double click from mouse

hey,
I looked in past threads and didn't get a proper answer for capturing both single and double click from the mouse.
in most applications the single click action does not interfere with the double click action, for example in a text editor, single click sets the cursor in between the text, double click marks a word, triple click marks a sentence, they do not bother each other, they all can happen first the single then the double and then the triple, but what if i have a very distinct action for each of the actions, the e.getClickCount() returns every time the number of clicks and if i use
if(e.getClickCount()==1)
    doSingleClick();
if(e.getClickCount()==2)
    doDoubleClick();it will always do first the single click and then the double click, which works fine with the example i gave, but not with what i want to do, so i was thinking to over come this that i will use another thread to run my tasks if dt has past since the last click and by the last click counts to perform the correct action and go to sleep until the next mouse click notify it, what do you think?
run this to get what i mean...
package blah;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MouseClickTest {
     static long previousTime = System.currentTimeMillis();
     public static void main(String[] args) {
          JPanel panel = new JPanel();
          JButton component = new JButton("Hit me, please");
          component.addMouseListener(new MouseAdapter(){
               public void mouseClicked(MouseEvent me){
                    if(me.getClickCount()==1)
                         System.out.println("Now I will do single click action");
                    if(me.getClickCount()==2)
                         System.out.println("Now I will do DOUBLE click action");
//                    System.out.println("Click count: " + me.getClickCount());
          panel.add(component);
          Launcher.launch(panel);
package blah;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Launcher {
     public static JFrame launch (Container contents, String title, Color backgroundColor) {
          JFrame frame = new JFrame (title);
          if (backgroundColor != null) {
               frame.setBackground (backgroundColor);
               contents.setBackground (backgroundColor);
          } else {
               frame.setBackground (contents.getBackground());
          frame.getContentPane().add (contents, BorderLayout.CENTER);
          frame.pack();
          frame.addWindowListener (new WindowAdapter() {
               public void windowClosing (WindowEvent e) {
                    System.exit (0);
          frame.setVisible (true);
          return frame;
     public static JFrame launch (Container contents, String title)      {
          return launch (contents, title, null);
     public static JFrame launch (Container contents, Color backgroundColor) {
          return launch (contents, contents.getClass().getName(), backgroundColor);
     public static JFrame launch (Container contents) {
          return launch (contents, contents.getClass().getName());
}

Read my comments and solution in this posting; [http://forums.sun.com/thread.jspa?forumID=57&threadID=705244]
and then choose a better design for your application.

Similar Messages

  • How to differentiate between Single click and double click event in List

    I am facing a problem while using list in awt.
    I want to execute some code on single click and other on double click but when double click event occurs it also executes the single click code.
    because i have added both actionlistener and itemlistener on the list.
    How to sort out this problem.
    please help me out.
    Thanks buddies.

    Hello Meeraj_Kanaparthi
    Thanks for helping i m giving u the code i have tried.
    Plz help me on this...
    Thanks........
    import java.awt.*;
    import java.awt.event.*;
    class CheckList extends Frame implements MouseListener
         List l1;
         int x;
         int y;
         CheckList()
         setSize(500,500);
         setLayout(new FlowLayout());
         l1=new List(10);
         add(l1);
         l1.add("Item 1");l1.add("Item 2");l1.add("Item 3");l1.add("Item 4");l1.add("Item 5");
         x=6;
         y=0;
         l1.addMouseListener(this);
    //     l1.addItemListener(this);
         show();
         public void execute(int y)
         if(y==1)
         {System.out.println("3");
              l1.remove(l1.getSelectedIndex());
         if(y==2)
         {System.out.println("4");
              l1.add("item " + x);
              x++;
         public void mousePressed(MouseEvent e)
              System.out.println("Pressed");
         public void mouseReleased(MouseEvent e)
              System.out.println("Released");
         public void mouseEntered(MouseEvent e) {}
         public void mouseExited(MouseEvent e) {}
         public void mouseClicked(MouseEvent e)
         if (e.getClickCount()==1)
              System.out.println("1");
              y=1;
         if (e.getClickCount() == 2)
         {System.out.println("2");
              y=2;
              execute(y);
         public void actionPerformed(ActionEvent ae)
         public void itemStateChanged(ItemEvent it)
         public static void main(String ag[])
         new CheckList();
    }

  • How can i perform the right click and double click operation in ipad.

    I have an email application i.e web application working fine in desktops, in that application if i will double click on the mail that mail will be open, and after opening that mail if i will right click on the mail it will show the different functionality .
    But i cant do that in ipad, is there solution to this problem ????

    mm.thejeshwini wrote:
    That application is a web-based application and the desktop version of the application has the functionality to open or pop-up a new window when double clicked on a particular text and now i want the same functionality to be performed on ipad. And some functionality to be worked for right-clicked also.
    I understand what you have and what you want. However, the iPad is not a desktop computer. What you want may not be possible. The developer may have already created an app specifically for the iPad. Have you checked the App Store?

  • How to have both Classic Report and Interactive Report from the same page?

    Hello APEX developers,
    I want to copy a page consisting of master-detail form together with its data, as in data stored in the tables.
    I've generated a master-detail form(which by default having its detail report as a classic report). I want to copy this page and then migrate this classic report to Interactive Report. This way, I have both the classic master-detail form with report AND the master-detail Interactive Report.
    I've tried doing this but ended up getting a new master-detail Interactive Report page without its data.
    Any feedback is appreciated.
    Best regards,
    Daniel

    Hi everyone,
    Solved already. What a relief! Kindly ignore this post.
    Rgds,
    Daniel

  • Mouse click - double click and right click

    How can i add a listeners to the mouse right click and double click?

    Double click is pretty easy. Just check the number of clicks you recieved as a result of the mouseClicked event of a MouseListener. Like so:
    public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2) {
    //double click
    }

  • Doubt - mouse double click invokes both single and double click

    Hi Friends,
    I added mouse listener to a java component. In the mouseClicked() method, I have implementation for both mouse single and double click. When I try to double click that component it invokes the single click method first and the it invokes the double click method. My problem is when I try to double click that component it should invoke my double click method alone not single click too.
    I'd be very grateful if someone can help me.
    Thanks and Regards,
    Sangeetha J

    Your problem: a double click is two single clicks. The first click will always fire a single-click event. How's the computer supposed to know that another click is to follow?
    All I think you could do is to instantiate a timer in the one-click method, set to whatever amount of time you think a double-click should take. If you get a second event while the timer's still active, it was a double-click and you can stop the timer and do the double-click action. Otherwise your timer should execute the single-click action after it timed out.
    But this will make your GUI look like it's responding slowly to single-clicks.

  • Programming button for single and double click

    I know how to programme a button to play a certain movie segment. However, in my current project I need to be able to programme a button in the menu so that
    1. on rollover - nothing
    2. on single mouse click - button colour changes + a parapraph of text appears on the menu screen in a predefined space
    3. on double click - a movie clip plays
    It might be a simple qiestion but I would greatly appreciate it if you could point me in the right direction.
    Thanks.

    Nick76 wrote:
    I know how to programme a button to play a certain movie segment. However, in my current project I need to be able to programme a button in the menu so that
    1. on rollover - nothing
    Do not change the highligh and it will look like nothing is happening (make sure auto activate is not beign used)
    2. on single mouse click - button colour changes + a parapraph of text appears on the menu screen in a predefined space
    3. on double click - a movie clip plays
    It might be a simple qiestion but I would greatly appreciate it if you could point me in the right direction.
    Thanks.
    Single and Double clicks cannot be done like that. (Some players using layered menus do require a click to get things seen but not really what you are speaking about.)
    Flash or Director may be better for this?

  • How do I set Firefox to automatically open downloads instead of having to go to my downloads and double click to open?

    Whenever I have used Firefox on a PC it at least gave me the option to open certain file types automatically. I download a lot of files and the time adds up when I have to open the downloads box and double click on the file each time.

    Hi,
    This could help you: [https://support.mozilla.org/en-US/kb/Managing%20file%20types#w_changing-download-actions Changing download actions]

  • Remediation for single-clicking a double-click action

    I'm using the double mouse click feature of a Click box in a
    software simulation lesson we've built in captivate. Unfortunately
    when the user single-clicks in the Click box, no remediation shows
    to tell the user that they must double-click in the box to complete
    the step.
    Anyone have any ideas on how to provide the user with
    remediation on single clicking a double click Click box?
    Thanks,
    Scott Witlen
    McKessson Provider Technologies

    Um... there are no macros. Captivate is a closed system with
    no documented API outside of some variables you can read and in
    some cases, set to make Captivate do some simple navigation-related
    things. Search the Captivate help file for 'variables' and you'll
    find a list.
    Outside of that, the only official ways to "enhance"
    Captivate are either to:
    - Create your own standalone functionality in Flash and
    insert it in Captivate as a self-contained animation. This can be
    problematic due to the closed nature of the Captivate runtime, as
    well as the layering imposed by the use of skins and borders.
    - Make Javascript calls to the browser and put the
    functionality there. Since there is limited interactivity between
    Javascript and Flash, this is much more limited in scope than
    inserting your own self-contained animations
    Some folks have also opened up a published SWF with a
    decompiler program and viewed the Adobe source code in an effort to
    make their inserted animations do cooler things, but that is very
    much an unsupported activity.

  • Preview 5.0.3 keeps hiding my text annotations, forcing me to find them 1 by 1 and double click on them to show their text, is there a way to show all?

    Somtimes, Preview 5.0.3 will hide my text annotations, forcing me to find them 1 by 1 and double click on them to show their text. After clicking on the Pen icon on the sidebar, i can see what slide numbers they are on, and have to go through 1 by 1 and double click them. For 200 slide classes, this becomes very annoying, is there a way to show all? or just to prevent it from hiding them in the first place?

    And to answer the tecnical aspects of your post in detail:
    --I want to know how to "see" what he has privately browsed
    You can't.
    -I want to know how to "see" what he has deleted.
    You can't.
    --I  want to know if being his IPhone 5s and Ipad 3 are synced, is what I have found on the Iphone (**** sites) but they are NOT on the Ipad, so does that mean he browsed privately, but forgot to click on "private" on the Iphone?   --
    What is browsed on one device has nothing to do with what is browsed on any other device. If you see something in a browser history in the iPhone, then either he didn't click "private" or didn't clear the history on that device.
    I also want to know if I synced both of our IPads, will what he looks at thru safari privately or not show up on my IPad Air? (most likely not, but I need to ask)
    No. Again, browser history is not synced to other devices.
    If he's surfing and either using Private Browsing or clearing the history, then there's no way you can see what sites he's visited. You'll just have to decide how to deal with that from there.
    Regards.

  • Leopard Registering Single Clicks as Double Clicks

    I have a terrible problem under 10.5.1 with the system registering about 40% of my single clicks as double clicks. It seems to be getting worse, as well. I thought it was an issue with the mouse on my Wacom tablet or with the Wacom driver, but in trying to troubleshoot it I found I had the same problem when using my original Apple mouse.
    It's extremely problematic. For example, I've customized my Finder toolbar to include the delete icon. However, if I click the delete icon and the system registers it as a double click, it will delete not only the file I intended, but it's parent directory. Is anyone else experiencing this?

    I have the same problem. I have concluded that it is a software problem either with OS X or some third party software on the computer.
    I originally thought it was a problem with Logitech's control center as that was the mouse I was having problems with. However, I recently replaced that mouse and uninstalled the logitech software and am still having problems with my new mouse from a different vendor. All the while, the trackpad will still register single clicks as double clicks.
    In my observations I found that once I restart the computer, single clicks will be registered as normal for the first few minutes of computer use. After that, any time the mouse is clicked more than once without being moved, no matter how much time has passed, it will register the subsequent clicks as double/triple/etc. clicks. So if, for example, I were to click an application icon once, not move the mouse, come back a day later and click again, it will double click. I also found that if the mouse is moved ever so slightly, it might still register as a double click.
    Additionally, if I am scrolling through any window but don't move the mouse, it will register the subsequent clicks as double clicks, even when you are clicking on a different item. An example of this is if I am scrolling down a finder window with a lot of files in column view, click on a file to see it's icon preview, then scroll down without moving the mouse and click on another file, it will register as a double click and launch that item.
    Other observations: I was having this problem in the early days of my OS install, so I went ahead and reinstalled the system. The problem came back in a day or so and I can't pinpoint it to any one piece of software that has been installed. I'm wondering if it is an OS issue.

  • In an album, many pictures would show on the screen and double clicking one would enlarge it for adjustments. Now one larger photo shows and along the bottom severa smaller ones. Options which used to be at the top right of screen no longer show. Whel

    In Aperture album about 16 photos would show on screen and double clicking on one would enlarge it for adjustments. Now one larger image shows with about 7 photos at bottom. Options for controlling this no longer appear at top right. How do I correct this?

    Do you mean the "View" controls are missing in your Toolbar?
    To add these controls back to the Toolbar, use the View menu and select "Customize Toolbar". Drag the View Controls back to the Toolbar.

  • I have just installed os7. How do I close apps when I double click on home button

    I have just installed os7. How do I close apps when I double click on home button

    Swipe to the app you want to close, press and hold the large image and swipe up and off the screen

  • How to get both OTF data and spool at a time

    Hi Experts,
        My requirement is to get both OTF data and spool.
    In 'OPEN_FORM' i tried passing itcpo-TDGETOTF = 'X'. itcpo- TDNEWID = 'X'.
    I was able to get OTF data but spool is not getting generated.
    IF i pass only itcpo- TDNEWID = 'X'. the spool is getting generated but not OTF data.
    when both the fields are set i.e. itcpo-TDGETOTF = 'X'. itcpo- TDNEWID = 'X'.
    the spool is generation is getting supressed.
    Similarly when i tried to get OTF data by passing itcpo-TDGETOTF = 'X'. to 'OPEN_FORM' as i need to convert it to PDF and send it to vendors as email ,
    The print preview in TCODE ME23n was not getting generated for 'MESSAGE' option 'External send'.
    Please suggest me how to get both OTF data and spool at a time.

    Hi Kartik,
    This one is similar to my question to print and email invoice at same time.  I pass itcpo-tdgetotf = 'X' in order to get otfdata and send email with the attachment of otfdata.
    Now I have data in otfdata, but when I call print_otf function, I clear out itcpo-tdgetotf, and passed
    itcpo-tddest = device_type but I still get error message said 'Handler not valid for open spool request'.
    Can you give me a working example that you have otfdata table and print data from that table.  I also post my question on other thread
    submit report and export to memory
    thanks

  • When I type I cannot add text when I select the text area and double click. Why?

    When I type I cannot add text when I select the text area and double click. Why?

    Premiere Elements 11  trial version for macMac computer photos uploaded to the timeline just finetrying to make a new title, streaming or in a framedouble clicked on the text in the box and nothing shows up when I type on my keyboard. I can delete the words that are there but not type in new ones. I selected the type and size, etc.
    Thanks if you can figure it out. I gave up!
    I may just un-install it all together if I can't get to work.Joanne
    Date: Thu, 9 May 2013 17:59:08 -0700
    From: [email protected]
    To: [email protected]
    Subject: When I type I cannot add text when I select the text area and double click. Why?
        Re: When I type I cannot add text when I select the text area and double click. Why?
        created by A.T. Romano in Premiere Elements - View the full discussion
    Joanne Murray J2 What version of Premiere Elements are you using and on what operating system (including 32 or 64 bit) is your Premiere Elements installed? Forgive the questions if you have been there and done that, but I do not want to take anything for granted that might hinder a speedy resolution to your issue. Are you opening an already created title that is sitting on the Timeline in order to edit it in the Titler or are you trying to create a new Title (Default Text or other)? Do you know how to work with the Selection Tool and Type Tool in the Titler? Once I know what version of Premiere Elements that you are using, I will give you specific how to details. Thanks. ATR
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5307494#5307494
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5307494#5307494
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5307494#5307494. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Premiere Elements by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

Maybe you are looking for