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

NullPointer in PopupMenuContainer caused by JTabbedPane with SCROLL_TAB_LAYOUT #314

Closed
xescote opened this issue Mar 8, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@xescote
Copy link

xescote commented Mar 8, 2022

Describe the bug
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "com.github.weisj.darklaf.ui.popupmenu.PopupMenuContainer.adjustSize(java.awt.Dimension, int, int)" because the return value of "com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI.getPopupMenuContainer()" is null
at com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI.getPreferredSize(DarkPopupMenuUI.java:135)
at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1725)
at com.github.weisj.darklaf.ui.tabbedpane.DarkScrollableTabSupport.actionPerformed(DarkScrollableTabSupport.java:92)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at com.github.weisj.darklaf.ui.button.DarkButtonListener.mouseReleased(DarkButtonListener.java:72)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6626)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3389)
at java.desktop/java.awt.Component.processEvent(Component.java:6391)

From the code we can see that getPopupMenuContainer() can return null when popupMenu is ScrollPopupMenu
So, when popupMenu is ScrollPopupMenu getPopupMenuContainer always returns null.

private PopupMenuContainer getPopupMenuContainer() {
    if (popupMenuContainer == null && !(popupMenu instanceof ScrollPopupMenu)) {
        popupMenuContainer = new PopupMenuContainer();
    }
    return popupMenuContainer;
}

To Reproduce

This happens when creating many JTabbedPane and they require a popup menu to show.
When click on the popup menu to show the hidden tabs the exception is thrown.

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;


public class BugPopupMenu {
	
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
	{
    	UIManager.setLookAndFeel("com.github.weisj.darklaf.DarkLaf");
		JFrame frame = new JFrame();
        SwingUtilities.updateComponentTreeUI(frame);
		JTabbedPane panel = new JTabbedPane();
		panel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
		for (int idx = 0; idx < 100; idx++)
			panel.addTab("Tab " + idx, new JPanel());
		frame.getContentPane().add(panel);
		frame.setSize(600, 500);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	}
}

Additional Information:

  • OS: [e.g. macOS]
  • Darklaf Version: [e.g. 2.7.3]
@xescote xescote added the bug Something isn't working label Mar 8, 2022
@weisJ
Copy link
Owner

weisJ commented Mar 23, 2022

This was fixed in d99c8a2, so the next version should resolve this issue.

@weisJ weisJ closed this as completed Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants