Note that there are some explanatory texts on larger screens.

plurals
  1. PONullpointerexception only with LaF Nimbus
    primarykey
    data
    text
    <p>I get a <code>Nullpointerexception</code> at <code>addPropertyChangeListener</code> when I am using Nimbus Look and Feel. When I use the Linux Standard LAF (Metal) everything works just fine.</p> <p>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).</p> <p>This is the Mainclass:</p> <pre><code>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); } </code></pre> <p>Here is the Panel Class:</p> <pre><code>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); } } </code></pre> <p>Like is said before, it works without any problem with Metal LAF</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload