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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:03:48+00:00 2026-05-23T01:03:48+00:00

JSpinner waitHr = new JSpinner(); waitHr.setEnabled(false); I have a spinner and I need to

  • 0
JSpinner waitHr  = new JSpinner();
waitHr.setEnabled(false);

I have a spinner and I need to prevent the user from editing it temporarily. The problem is, when the spinner is disabled, it’s text colour makes it very hard to read, which is not acceptable in this case. I noticed that you can do this with JTextFields:

 JTextField txtTest   = new JTextField();
 txtTest.setDisabledTextColor(Color.BLACK);

Is there anything similar that can be used for a JSpinner?

  • 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-23T01:03:48+00:00Added an answer on May 23, 2026 at 1:03 am

    you can play with that as you want

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.LineBorder;
    
    public class InactiveBackgroundTest {
    
        public JComponent makeUI() {
            JSpinner s0 = new JSpinner();
            s0.setPreferredSize(new Dimension(100, 20));
            s0.setEnabled(false);
            UIManager.put("FormattedTextField.inactiveBackground", Color.RED);
            JSpinner s1 = new JSpinner();
            s1.setEnabled(false);
            s1.setPreferredSize(new Dimension(100, 20));
            JSpinner s2 = new JSpinner();
            s2.setEnabled(false);
            s2.setPreferredSize(new Dimension(100, 20));
            JTextField field = ((JSpinner.NumberEditor) s2.getEditor()).getTextField();
            field.setEditable(false);
            field.setBackground(UIManager.getColor("FormattedTextField.background"));
            JSpinner s3 = new JSpinner();
            s3.setPreferredSize(new Dimension(100, 20));
            s3.setEnabled(false);
            s3.setBorder(null);
            JTextField tf = ((JSpinner.DefaultEditor) s3.getEditor()).getTextField();
            tf.setDisabledTextColor(Color.black);
            tf.setBackground(Color.white);
            tf.setBorder(new LineBorder(Color.blue, 1));
            s3.setBorder(new LineBorder(Color.red, 1));
            int n = s3.getComponentCount();
            if (n > 0) {
                Component[] components = s3.getComponents();
                String compName = "";
                for (int i = 0, l = components.length; i < l; i++) {
                    if (components[i] instanceof JButton) {
                        JButton button = (JButton) components[i];
                        if (button.hasFocus()) {
                            String btnMane = button.getName();
                        }
                        button.setBorder(new LineBorder(Color.red, 1));
                        System.out.println("JButton");
                    } else if (components[i] instanceof JComboBox) {
                        System.out.println("JComboBox");
                    } else if (components[i] instanceof JTextField) {
                        System.out.println("JTextField");
                    } else if (components[i] instanceof JFormattedTextField) {
                        System.out.println("JFormattedTextField");
                    } else if (components[i] instanceof JTable) {
                        System.out.println("JTable");
                    } else if (components[i] instanceof JScrollPane) {
                        System.out.println("JScrollPane");
                    } else if (components[i] instanceof JPanel) {
                        JPanel panel = (JPanel) components[i];
                        panel.setBackground(Color.red);
                        panel.setBorder(null);
                        System.out.println("JPanel");
                    }
                }
            }
            JPanel p = new JPanel();
            p.setBackground(Color.black);
            p.add(s0);
            p.add(s1);
            p.add(s2);
            p.add(s3);
            return p;
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    
        public static void createAndShowGUI() {
            try {
                //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
                    if ("Windows".equals(laf.getName())) {
                        UIManager.setLookAndFeel(laf.getClassName());
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            f.getContentPane().add(new InactiveBackgroundTest().makeUI());
            f.setPreferredSize(new Dimension(120, 140));
            f.setLocationRelativeTo(null);
            f.pack();
            f.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get value from JSpinner. private JSpinner[] timeSpinner; private SimpleDateFormat format =
I have a jspinner in the format yyyy-MM-dd hh:mm:ss . The problem is the
I have a JSpinner with a Number Editor along the lines of: JSpinner spinner
I have a problem with the standard JSpinner.DateEditor (as probably does everyone else). When
I have a problem invoking the fireStateChanged() method for a JSpinner. I create a
I have a JSpinner that displays decimal values from 0.0 to 999.0. It seems
i'm using a JSpinner like a table cell editor, i have one annoying problem:
I have a jSpinner with a SpinnerNumberModel like this: spinnerModelFix = new SpinnerNumberModel(0, 0,
I need to validate the user input of a JSpinner , and if invalid,
GUI i am trying to use JSpinner but as you can see from the

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.