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

The Archive Base Latest Questions

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

I need to create some JSpinner controls where I can detect the button presses,

  • 0

I need to create some JSpinner controls where I can detect the button presses, whilst using the current look and feel. I have found I can do this easily enough as follows:

class CustomSpinnerUI extends BasicSpinnerUI {
    @Override
    protected Component createNextButton() {
        // Add custom ActionListener.
    }

    @Override
    protected Component createPreviousButton() {
        // Add custom ActionListener.
    }
}

The problem is that by doing this I end up with a nasty-looking spinner which doesn’t use the same look and feel as the rest of my UI. I’m currently using Nimbus but I need to support different L&F configurations.

I thought about possibly setting up some sort of dynamic proxy, but couldn’t find any suitable Spinner interfaces to enable me to do that.

Can anyone think of a way around the problem? I figure I either need to get at the button ActionListeners without subclassing BasicSpinnerUI, or work out a way to have my CustomSpinnerUI use the correct L&F.

Edit: “default look and feel” -> “current look and feel”.

  • 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:43:12+00:00Added an answer on May 26, 2026 at 1:43 am

    a dirty technical answer to (concededly assumed) problem “how to access the buttons for hooking-in a custom actionListener” is to loop through the spinner’s children and add the listeners to the buttons, identified by their name:

        JSpinner spinner = new JSpinner();
        Action action = new AbstractAction() {
    
            @Override
            public void actionPerformed(ActionEvent e) {
                LOG.info("button " + ((Component) e.getSource()).getName());
            }
        };
        for (Component child : spinner.getComponents()) {
            if ("Spinner.nextButton".equals(child.getName())) {
                ((JButton) child).addActionListener(action);
            }
            if ("Spinner.previousButton".equals(child.getName())) {
                ((JButton) child).addActionListener(action);
            }
        }
    
    • that’s dirty because it relies on an undocumented implementation detail which a LAF may or may not respect: Metal, Nimbus do; Win doesnt (which I consider an oversight but that’s a different story 🙂
    • it is technical only, as the real problem seems to be somewhere else, judging by a recent comment on the question
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several web services I need to create for them some testing mechanism
I need to create a slide show of some images that can go full
we have some C++ code that we need to create a make file in.
We are using Nant to deploy an application and need to create some MSMQ
I have content type with Photos ImageField. I need to create some moderation view
Need to create some table so I can get an info from it in
I need to create some type of Quizz app witch have to have 2
I need to create some simple graphics using java. Basically what I need to
I need to create some files using Visual Studio T4 (templating). What is the
I would need to create some webpages that are using jscript and different jscript

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.