Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in combobox with custom renderer after switching to FlatLaf #16

Closed
kirill-grouchnikov opened this issue Oct 21, 2019 · 1 comment

Comments

@kirill-grouchnikov
Copy link

public class Test {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(new NimbusLookAndFeel());
                } catch (Throwable t) {
                    t.printStackTrace(System.err);
                }

                JComboBox comboColors = new JComboBox<>(new Color[] {new Color(255, 128, 128),
                        new Color(128, 255, 128), new Color(128, 128, 255), new Color(255, 255, 128),
                        new Color(255, 128, 255), new Color(128, 255, 255)});

                comboColors.setRenderer(new DefaultListCellRenderer() {
                    @Override
                    public Component getListCellRendererComponent(JList list,
                            Object value, int index, boolean isSelected,
                            boolean cellHasFocus) {
                        Color color = (Color) value;
                        Component result = super.getListCellRendererComponent(list,
                                color.getRed() + ":" + color.getGreen() + ":" + color.getBlue(),
                                index, isSelected, cellHasFocus);
                            result.setBackground(color);
                        return result;
                    }
                });

                JButton toFlat = new JButton("Set FlatDark!");
                toFlat.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    UIManager.setLookAndFeel("com.formdev.flatlaf.FlatDarkLaf");
                                    for (Window w : Window.getWindows()) {
                                        SwingUtilities.updateComponentTreeUI(w);
                                    }
                                } catch (Throwable t) {
                                    t.printStackTrace(System.err);
                                }
                            }
                        });
                    }
                });

                JFrame frame = new JFrame("Combo test");
                frame.setLayout(new BorderLayout());
                frame.add(comboColors, BorderLayout.NORTH);
                frame.add(toFlat, BorderLayout.SOUTH);
                frame.setSize(400, 400);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }
}

Click the "Set FlatDark!" button and then click the combo at the top. Result:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at java.desktop/javax.swing.plaf.basic.BasicComboPopup.getPopupHeightForRowCount(BasicComboPopup.java:1283)
	at java.desktop/javax.swing.plaf.basic.BasicComboPopup.getPopupLocation(BasicComboPopup.java:1369)
	at java.desktop/javax.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:234)
	at java.desktop/javax.swing.plaf.basic.BasicComboPopup.togglePopup(BasicComboPopup.java:1218)
	at java.desktop/javax.swing.plaf.basic.BasicComboPopup$Handler.mousePressed(BasicComboPopup.java:897)
	at java.desktop/java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:287)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6633)

This is on 0.14

JFormDesigner pushed a commit that referenced this issue Oct 21, 2019
@JFormDesigner
Copy link
Owner

many thanks, fixed in 0.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants