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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:25:07+00:00 2026-06-03T15:25:07+00:00

I get a Nullpointerexception at addPropertyChangeListener when I am using Nimbus Look and Feel.

  • 0

I get a Nullpointerexception at addPropertyChangeListener when I am using Nimbus Look and Feel. When I use the Linux Standard LAF (Metal) everything works just fine.

Here is a small Testproject which simulates the problem! I have a Class which extends JPanel and provides to Content to a Frame. The Finsih button on the frame will only be enabled when some conditions are met (in this case the button2 is pressed).

This is the Mainclass:

public class Main extends JFrame {

    /**
     * 
     */
    private static final long serialVersionUID = -3120562776241721109L;
    private JPanel contentPane;
    private JButton button;
    private PropertyChangeListener changeListener;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {


        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Main frame = new Main();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Main() {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            System.out.println(UIManager.getLookAndFeel());
        } catch (ClassNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InstantiationException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedLookAndFeelException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

        button = new JButton("BUTTON");
        button.setEnabled(false);
        changeListener = new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equalsIgnoreCase("state")) {
                    button.setEnabled((boolean) evt.getNewValue());
                }
            }
        };
        contentPane.add(button, BorderLayout.SOUTH);
        Panel panel = new Panel();
        contentPane.add(panel, BorderLayout.CENTER);
        panel.addPropertyChangeListener(changeListener);
    }

Here is the Panel Class:

public class Panel extends JPanel {
    /**
     * 
     */
    private static final long serialVersionUID = -5036784576513445229L;
    private PropertyChangeSupport changes;
    private boolean state;
    /**
     * Create the panel.
     */
    public Panel() {

        this.changes = new PropertyChangeSupport(this);
        JButton button = new JButton("BUTTON2");
        add(button);
        state = false;
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                state = !state;
                changes.firePropertyChange("state", null, state);
            }
        });

    }

    @Override
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changes.addPropertyChangeListener(listener);
    }
}

Like is said before, it works without any problem with Metal LAF

  • 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-03T15:25:08+00:00Added an answer on June 3, 2026 at 3:25 pm

    Looks like you override addPropertyChangeListeners and you store the listeners in an List called “changes”. Since the UI is installed before the rest of your constructor is executed, your changes variable has not been initialized.

    Add a null-test before adding the listener to your List and instantiate the List if needed (and do the same in your constructor as well). I can’t remember if initializing the variable inline could work or not (and I don’t have a JDK here to test and tell you that).

    Or consider not overriding that method. Why did you do that in the first place? It looks unnecessary (but I can’t tell precisely without the code).

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

Sidebar

Related Questions

I am just trying to fill my ListView but I get a NullPointerException Here
I'm having trouble using a selectOneRadio component. I get a NullPointerException in my Converter's
I'm trying create a connection using Spring 3.2.0 but I get NullPointerException of: ApplicationContext
I use a spinner in my ListActivity and get a NullPointerException at setAdapter method.
I get a NullPointerException in my onCreate method in some activities. It's hard to
When I try to call any GL15 function in lwjgl I get A NullPointerException.
It doesn't seem to be working right now. I get a java.lang.NullPointerException I have
i get NullPointerException at the start of the for where am i going wrong?
I get a NullPointerException when a url passed in webview in an activity (the
I get a NullPointerException calling a Superclass Method in Subclass Inner Class Constructor... What's

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.