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 8091591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:05:59+00:00 2026-06-05T20:05:59+00:00

This is getting me quite confused: I have a small application that uses a

  • 0

This is getting me quite confused:
I have a small application that uses a JSpinner for numeric values. I added a MouseAdapter to it, setting the value depending on the resulting event’s getScrollAmount() and getWheelRotation().

Everything is working quite fine as long as the application is run on linux (Debian Wheezy, Oracle JDK 1.6.0_32). That is, scrolling the mouse wheel while the JSpinner has focus works just fine (using GTK LookAndFeel).

Testing the software on Microsoft Windows exposed a different behavior:
The JSpinner will not react on mouse wheel movement. LookAndFeels don’t seem to be a problem here, as i already tried MetalLookAndFeel on both Linux and Windows.

Any suggestions on how to get this JSpinner reacting on MouseWheelEvents on both OSes?

Thank you.

  • 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-06-05T20:06:00+00:00Added an answer on June 5, 2026 at 8:06 pm

    Hmm im not sure what could be wrong, but here is code designed on windows 7 and it works fine so maybe try it out on yours and see where the code is different:

    import java.awt.Container;
    import java.awt.EventQueue;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import javax.swing.JFrame;
    import javax.swing.JSpinner;
    import javax.swing.UIManager;
    import javax.swing.UIManager.LookAndFeelInfo;
    
    /**
     *
     * @author David
     */
    public class JSpinnerMouse extends JFrame {
    
        private JSpinner jspinner;
    
        public JSpinnerMouse() {
            createAndShowUI();
        }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            try {
                for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (Exception e) {
                // If Nimbus is not available, you can set the GUI to another look and feel.
            }
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    JSpinnerMouse jSpinnerMouse = new JSpinnerMouse();
                }
            });
        }
    
        private void createAndShowUI() {
            setTitle("JSpinner using mouse wheel");
            setSize(300, 300);
            setResizable(false);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationRelativeTo(null);
            addComponentsToContentPane(getContentPane());
            addListeners();
            setVisible(true);
        }
    
        private void addComponentsToContentPane(Container contentPane) {
            jspinner = new JSpinner();
            contentPane.add(jspinner);
        }
    
        private void addListeners() {
            this.addMouseWheelListener(new MouseWheelListener() {
    
                @Override
                public void mouseWheelMoved(MouseWheelEvent mwe) {
                    if (MouseWheelEvent.WHEEL_UNIT_SCROLL == mwe.getScrollType()) {
                        int value = (int) jspinner.getValue();
                        if (mwe.getWheelRotation() == -1) {//up
                            jspinner.setValue(value + 1);
                        } else {//down
                            jspinner.setValue(value - 1);
                        }
                    }
                }
            });
        }
    }
    

    Also to mention, I could not find the getDirection() method in the MouseWheelEvent like you said you are using so i used the getUnitsToScroll() which will return either a positive or negative value depending on the direction. Maybe this is whats causing the trouble. Where did you find a getDirection() method in the MouseWheelEvent Class?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting quite confused as to where I am getting this compiler error
I am getting started with using ValidationRules in my WPF application, but quite confused.
Im getting this linker error that won't let me compile. It only happens on
I have a quick question regarding memory management that I am not quite sure
I am getting confused between domain/application logic and User Interface logic. To illustrate what
I've spent many hours trying to get this to work. And I'm getting quite
So, say I have an array that looks like this: t = [ [
I am getting quite confused with different opinion from diff people and the developer
This question's quite stupid, but I'm having trouble getting wpml to translate my plugin.
Im getting very confused with indexes in MySQL. I have two tables: TableA1 and

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.