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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:23:33+00:00 2026-06-18T08:23:33+00:00

I want to change my componentstyle by using UIManager. For example: I click on

  • 0

I want to change my componentstyle by using UIManager.

For example:

I click on a Button and the Button foreground changes from black to green. The same for a JCheckbox…..

In my example the changes just work for the Button.gradient…. I get no update for Button.foreground and no update for the JCheckbox!

Here my UIManagerClass:

  package components;

import java.awt.Color;
import java.util.ArrayList;
import javax.swing.SwingUtilities;


public class OwnUiManager {

    ButtonDemo Bd;

    OwnUiManager(ButtonDemo aThis) {
        Bd = aThis;
    }

    public void setNormal() {
        ArrayList<Object> gradients = new ArrayList();
        gradients.add(0.3);
        gradients.add(0.0);
        gradients.add(new Color(221, 232, 243));
        gradients.add(new Color(255, 255, 255));
        gradients.add(new Color(184, 207, 229));
        javax.swing.UIManager.put("RadioButton.background", Color.PINK);
        javax.swing.UIManager.put("Button.gradient", gradients);
        javax.swing.UIManager.put("Button.foreground", Color.PINK);
        SwingUtilities.updateComponentTreeUI(Bd);
    }

    public void setNightVision() {
        System.out.println("Tes");
        ArrayList<Object> gradients = new ArrayList();
        gradients.add(0.18f);
        gradients.add(0.17f);
        gradients.add(Color.BLACK);
        gradients.add(Color.DARK_GRAY);
        gradients.add(Color.DARK_GRAY);
        javax.swing.UIManager.put("RadioButton.background", Color.GRAY);
        javax.swing.UIManager.put("Button.gradient", gradients);
        javax.swing.UIManager.put("Button.foreground", Color.red);

        SwingUtilities.updateComponentTreeUI(Bd);
    }
}

and here my Buttondemo/Main-Class:

package components;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class ButtonDemo extends JPanel
        implements ActionListener {

    protected JButton b1,b2;
    private JRadioButton b3;

    public ButtonDemo() {

        b1 = new JButton("ON");
        b1.addActionListener(this);
        add(b1);
        b2 = new JButton("OFF");
        b2.addActionListener(this);
        add(b2);
        //For Testing the Style
        b3=new JRadioButton("Test");
        add(b3);
    }

    public void actionPerformed(ActionEvent e) {
        OwnUiManager test = new OwnUiManager(this);
        if (e.getSource().equals(b1)) {
            test.setNormal();
        } else {
            test.setNightVision();
        }
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame("ButtonDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ButtonDemo newContentPane = new ButtonDemo();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        frame.pack();
        frame.setVisible(true);
    }


    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
  • 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-18T08:23:34+00:00Added an answer on June 18, 2026 at 8:23 am
    • JCheckBox / JRadioButton has Icon

    • have to change own Icon to concrete JCheckBox / JRadioButton or put then to the UIManager, then apply for whole JVM instance

    • for more infos have to check UIManager Defaults and Key Bindings by camickr

    • most of your potential issues is descibed in Creating a custom button in Java with JButton

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

Sidebar

Related Questions

I want to change EditText visibility to hidden when a button click. I write
I want to change content of a Button in XAML using a DataTrigger. Conditionally
I want change my class=value on select option using jQuery Example <select name=color_scheme id=color_scheme>
i want change the content of a UITableView when i change a button, how
I have a RadioButtnList. I want change body background color based on radio button
i have many div's with the same background image and i want change this
I want change the cells order in my tableview I am using following code
I have two radio button on change event i want change button How it
I want change background picture(a div) with javascript that I will take from database.
I want change the HBox's style when click any object inside this HBox. I

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.