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

Similar Messages

  • Mail: how to download ONLY last emails and not the whole hotmail.

    Hi!
    Quick question: like what Mail does in iPhones/iPads, how can I configure Mail in my iMac or Macbook Pro so that it only downloads the last, say 50 emails and not the 4000 aprox. emails I have inside the hotmail (now outlook) server?
    I have been wanting to use mail for a long time but I can't seem to find that option. I only want to see the LAST EMAILS like what happens in the app on my iPhone.
    Thanks.

    unless there is a special setting in yahoo webmail interface that allows this (gmail pop has it for example), there is no way to do it. POP will download all available messages on the first download. that's how POP works. from there on it will only download new ones.

  • How can I only send imessages and not texts on my iphone 4S

    I have turned OFF Send as SMS on the settings of my iphone. However the phone still allows me to send text messages using the message facility. I am aware that green equals text and blue equals imessage.
    I would however like to disable or at least have a reminder before sending a text in order that I do not get billed for sending photos attached to text instead of as imessages
    I thought that turning OFF Send as SMS in the settings field would prevent me sending texts and only allow imessages to go out, but this does not seem to be the case
    Regards
    Dave

    You can turn off sending pictures messages except as iMessages by going to Settings>Messages>MMS Messaging and setting it to "Off".

  • I have to "single-click" twice (not double click) to open an item in the Dock.

    Can someone confirm if this is Expected Behavior??   (OS = Mavericks)
    If you have Assigned an application in your Dock to a Desktop & Display in the application's Dock >> Options  (ex: Assigned To:  Desktop on Display 2):
    Click once on the application icon in the Dock, the application's Menu will populate on the top of your screen, but not the application itself (yet), click the application icon a second time, the application will now show too. 
    Docked Applications that do not have an Assigned To: Desktop & Display in the Dock options, you only need to single click.
    FYI:
    For odd Dock behaviors otherwise try this:
    You may have a corrupted Dock preferences file.
    Open the Finder. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following:
    ~/Library/Preferences/com.apple.dock.plist    (plist = preference list file)
    Click Go then move the com.apple.dock.plist file to the Trash, or move it to your Desktop.
    Restart your Mac and see if the behavior is resolved.  You will have re-configure your Dock settings.

    From where are you launching Mail? The only place, unless I've missed or forgotten something, you can launch an application with a single click is from the Dock. Is this what you're doing, or are you attempting to launch Mail from the Applications folder?
    Regards.

  • How do you move a single album, and not the whole library, in iPhoto to an external hard drive?

    How do you move a single album, and not the whole library, in iPhoto to an external hard drive?

    File -> Export to a folder and copy it over.
    That will give you a folder with the images. There is no way to move an album outside of iPhoto. You would need to have a library containing it.
    Regards
    TD

  • HT4889 How do you only migrate pictures and music? I do not want to migrate anything else. Thank you for your time.

    How do you only migrate pictures and music? I do not want to migrate anything else. Thank you for your time.

    Welcome to the Apple Support Communities
    Migration Assistant will ask you what you want to migrate from your old Macintosh, so select just Pictures and Music

  • How to make google come up and not yahoo when i click anew tab

    how to make google come up and not yahoo when i click a new tab
    == This happened ==
    Every time Firefox opened
    == today

    You can use 1 of these add-ons
    [https://addons.mozilla.org/en-us/firefox/addon/newtaburl/?src=search
    NewTabURL ]
    [https://addons.mozilla.org/en-us/firefox/addon/new-tab-homepage/?src=search New Tab Homepage]
    with NewTabUrl you have more options
    thank you
    Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

  • How can I save my keynote presentation as one single file and not a folder

    I use the latest kerynote version and I would like to upload the presentation as a single file to a collaboration solution.
    How can I save my presentation as one single file and not as a folder?

    Keynote "files" are not single files, they are packages which contain all the individual files that the presentation requires.
    Some online storage systems such as Google Drive show Keynote as a folder.
    We use Dropbox to distribute all our file types and Keynote does not have an issue using that.

  • How do you add full folders and not just individual files in the new itunes?

    How do you add full folders and not just individual files in new itunes? i just reformatted my HD and went to add all my music and it's only letting me add files not folders!?!?

    "Add Folder to Library" is still in the file menu, but you might need to bring up the menu bar to see the file menu.
    If you're using 11.0.x, click on the wee boxy icon up in the top-left corner of your iTunes to see the "Show Menu Bar" control, as per the following screenshot:

  • When I am on a phone call and I double click the button to go to my home screen, then open another application (usually my calendar program, Calengoo), my screen goes blank and I am not able to return to either the app, the phone, or the home screen.

    When I am on a phone call and I double click the button to go to my home screen, then open another application (usually my calendar program, Calengoo), my screen goes blank and I am not able to return to either the app, the phone, or the home screen. If I am speaking to a person, if they hang up then I am back to the phone application. If I'm leaving a message, I am unable to return to the phone screen to end the call, and have to wait until the other phone hangs up. I'm also unable to switch back and forth to look at my calendar if I'm calling someone about scheduling. This has only started happening since the most recent iOs update. I run into situations similar to this about once per day during the work week, as I use my phone is this manner quite often. While not life altering it is quite frustrating. Can anyone here help me figure out a way to avoid this? If it helps, I have noticed a general downgrade in overall performance starting two system updates ago (apps opening more slowly, closing unexpectedly more often, etc.). I have an iPhone 3GS with the latest OS update.
    Thank you for any help or suggestions,
    Chris

    I could be corrupted backup.
    You can check the notification settings for message.
    Settings>Notification Center>Messages>Alert Style
    It should be on Banners or Alerts.
    Settings>Messages> Turn on Imessage and send as SMS and below that "Blocked" to check if you have any numbers block might be blocking the message.
    You can also do a hard reset by holding power and home till it restarts and release after seeing the apple logo.
    Still doesn't work? Settings>General>Reset>Reset all settings

  • When insert my lexar USB flash drive I get the message that the disk was not readable by this computer.  It has worked previous to this and I do not want to lose the data by reformatting the drive.  How can I reformat this drive and not lose my data?

    When insert my lexar USB flash drive I get the message that the disk was not readable by this computer.  It has worked previous to this and I do not want to lose the data by reformatting the drive.  How can I reformat this drive and not lose my data?

    You can't reformat it and not wipe everything on it.
    Have you tried a different USB port?
    Only other option, back it up on a different computer.

  • I want to delete a few contacts, apps, pics etc from my iphone, but when I delete and connect to my laptop they sync and come back again. How can I delete those items and not get them back when I connect my iphone to my laptop?

    I want to delete a few contacts, apps, pics etc from my iphone, but when I delete and connect to my laptop they sync and come back again. How can I delete those items and not get them back when I connect my iphone to my laptop?
    Also where exactly on the laptop is teh data stored.
    Thank you!!

    go to 'Edit' in the menu bar. Then choose 'Preferences'.
    you'll see a pop-up and there's a tab called 'Devices' there. If you click that, you will be able to check a box that says 'prevent automatic syncing for iPods, iPads and iPhones' or something like that.
    Hope this helps
    NB: if you don't even see the menu bar that has options like 'File, Edit, View, etc', first click the black/white square button on the top left of your screen, and then click 'show menu bar'. It should pop right up.
    Good luck

  • Airport utility only shows disc and not airplay

    airport utility only shows disc and not airplay

    Actually......IF......one is using an older 5.x version of AirPort Utility......AND.....an AirPort Express, a Music icon is displayed at the top of the screen. If you click the Music icon, there are settings to enable AirPlay and establish a password for the service.
    The newer Mac 6.x and iPad and iPhone versions of AirPort Utility automatically enable AirPlay, but display no settings for this.
    Since ralphington is using Mavericks (10.9.4), there are no controls for AirPlay displayed in his version of AirPort Utility.

  • I am able to search only by text and not by Key in filter.

    We have a variable x which has bex properties in the infoobject level to
    1.display:   Key and Text
    2.text type: long text
    3.Query def filter value selection: Only values in infoprovider
    4.Query Exe filter value selection: Only posted values for navigation.
    in the Query designer to the object we have the same properties for 1 and 2 as above.
              On execueting the report in web,  In the variable screen for x <b>we can search for both Key and text</b>. (we have two radio buttons for Key and text),
               Whereas in the <b>result area for the filter</b> for x I am able to search <b>only by text and not by Key</b>. I want to search by both Key and text in filter screen. 
    Can u suggest suitable solution for this ASAP.

    I have been working on a similar problem and have found that it depends on what kind of InfoProvider you are using.
    If you are using an InfoCube, the setting that seems to control this is on the maintenance screen (Admin Workbench -> {InfoProvider to be edited} -> Change -> Extras -> Structur-Specific InfoObject Properties. If you want the key and text to display on the variables screen (which you already have), make sure the 'Display' is set to "Key and Text". If you want key and text to display on the filter screen, make sure the 'F4 Query' is set to "Values in Master Data Table". (You may also have to set the characteristic to display key and text in the query, but it sounds like you already have done this.)
    For an ODS, the settings are the same, but the path to get there is different. Go to Admin Workbench -> {ODS to be edited} -> Change -> {InfoObject to be edited} -> Right-click -> ODS-object Specific Properties. Same settings as above after this.
    For a MultiProvider, I found that the settings on the InfoObject itself seemed to control the display on the Web, so I ended up setting: Display = "Key and Text"; Query Def Filter Value Selection = "Values in Master Data Table"; and Query Exe Filter Value Selection = "Values in Master Data Table". That may be a bit of overkill, but I wanted to be sure to get both key and text in all situations.
    I also found that the settings for navigational attributes (e.g., 0PLANT__0REGION) for any kind of InfoProvider must be set at the InfoObject level (e.g., 0REGION), as above.
    Even with all of this, I still have a couple of InfoObjects left that I can't get to display both key and text for some unknown reason.
    Hope this helps...
    Bob

  • How to delete iCloud email address and not iCloud service

    how to delete iCloud email address and not iCloud service.
    It is very anoying that I can't cancel icloud email address. Can someone help me?

    You can't delete either the account or the email address. If you are getting messages to it you don't want to see, go to http://icloud.com and to the Mail page: click on the cogwheel icon at bottom left and choose 'Rules'. Then set up a Rule to move all messages to your address to the Trash.

Maybe you are looking for

  • Ipod(s) are not syncing with itunes all of a sudden

    WARNING, this is going to be very long-winded.  So I've exhausted every avenue I can think of myself, so I figured I'd try just asking on the forum here and hopefully someone can suggest a solution.  First, the specs of the equipment/software involve

  • Jars and classpath

    Hi All, I have a command line program which access database and somehow connects to a servlet running in Tomcat. Originally, the root directory has 2 sub-directories: the classes and the lib. The classes directory contains config files, like database

  • World Minutes not working on O365 Home Premium Sub...

    I have 60 monthly World Minutes for Office 365.  The subscription is active with 60 minutes left. I am in the US in a Chicago suburb, and am trying to call a mobile number in the UK.  The skype account I am using is via the Microsoft account - eg the

  • Where can i find this num

    Hiya i got an Extigy and i need to know where i can find this number on the device:?Previous 6 or 7 digit CRS number or RMA No... thank you

  • Master data Load - Strategy

    Hi All, I would like to know the better master data strategy. When using 3.x master data load strategy I can load directly into the info object without going thru additional DTP process. Is there any specific advantages of doing this, besides that it