Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6653025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:12:57+00:00 2026-05-26T01:12:57+00:00

I have a Swing application that deals with date and time, so a lot

  • 0

I have a Swing application that deals with date and time, so a lot of tests are done changing the system’s date and time settings.
During the tests, we noticed that after decreasing the clock, the first click is ignored by the application.

Is it a bug of Swing/Java/Windows? Is there a workaround to this?

Interestingly, this issue only happens when decreasing the date/time settings. If I increase it, the application behaves normally.

Situation:

  • Swing application running.
  • Decrease Windows date and time settings (e.g. change time from 15:00 to 14:00).
  • Notice that the first click in the Swing application does not fire any action.

Code example (you can use it to testify the situation):

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;

    import javax.swing.JButton;
    import javax.swing.JFrame;

    public class Main {

        public static void main(String[] args) {
            final JFrame frame = new JFrame("frame");
            final JButton button = new JButton("button");
            button.addActionListener(new ActionListener() {

                public void actionPerformed(final ActionEvent e) {
                    System.out.println("Button Pressed!");
                }
            });

            frame.add(button);
            frame.setSize(200, 200);
            frame.setVisible(true);
            frame.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosing(final WindowEvent e) {
                    System.exit(0);
                }
            });
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:12:57+00:00Added an answer on May 26, 2026 at 1:12 am

    I’ve debugged it via Eclipse and found out what is happening.

    • Clock at 15:00h.
    • Click at the button. Swing record last event time to 15:00.
    • Change the clock to 14:00h.
    • Click at the button. Swing ignores the event because it looks like a multi-click.

    The problem here is that the comparison made by Swing checking for multi-click is this:

    if (lastTime != -1 && currentTime - lastTime < multiClickThreshhold) {
        shouldDiscardRelease = true;
    

    Here, currentTime - lastTime yields a negative value. It’s less than 0 (my multiClickThreshhold), so it does not fire the action event:

    public void mouseReleased(MouseEvent e) {
        if (SwingUtilities.isLeftMouseButton(e)) {
            // Support for multiClickThreshhold
            if (shouldDiscardRelease) {
                shouldDiscardRelease = false;
                return;
            }
            AbstractButton b = (AbstractButton) e.getSource();
            ButtonModel model = b.getModel();
            model.setPressed(false);
            model.setArmed(false);
        }
    }
    

    All the source listed above is in javax.swing.plaf.basic.BasicButtonListener.

    The Button class does have a setMultiClickThreshhold, but it throws IllegalArgumentException in case the threshhold is less than 0.

    So, as a workaround, I did this:

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.lang.reflect.Field;
    
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class Main {
    
        public static void main(String[] args) throws Exception {
            final JFrame frame = new JFrame("frame");
            final JButton button = new JButton("button");
            removeMulticlickThreshold(button);
    
            button.addActionListener(new ActionListener() {
    
                public void actionPerformed(final ActionEvent e) {
                    System.out.println("Button Pressed!");
                }
            });
    
            frame.add(button);
            frame.setSize(200, 200);
            frame.setVisible(true);
            frame.addWindowListener(new WindowAdapter() {
    
                @Override
                public void windowClosing(final WindowEvent e) {
                    System.exit(0);
                }
            });
        }
    
        private static void removeMulticlickThreshold(final JButton button) throws Exception {
            final Field multiClickThreshhold = AbstractButton.class.getDeclaredField("multiClickThreshhold");
            multiClickThreshhold.setAccessible(true);
            multiClickThreshhold.set(button, Long.MIN_VALUE);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a swing Java application that preserves a lot of data (you can
I have a swing application that freezes after some (random) time. I have taken
I have a Swing application that is heavy customised with a lot of custom
My system: I have a java swing application that is running on Solaris 10/X86
I have a Swing application that connect directly to MySql Database for user authentication.
I have a swing application that uses some datas coming from an external mysql
i have a swing application that i would like to run on os x
I have a Swing application that I would like to convert from spaghetti to
I have a Java Swing application that is being used as a cluster application.
So I have a strange problem, I have a java swing application that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.