JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.42k stars 272 forks source link

Endless loop if button in Toolbar has focus and is made invisible #884

Closed PikeTec closed 1 month ago

PikeTec commented 2 months ago

If a focusable button is hidden while it has the focus, the UI fill freeze due to an endless while loop executed in the AWT Thread.

A minimal a example is

  public static void main(String[] args) throws UnsupportedLookAndFeelException {
    UIManager.setLookAndFeel(new FlatLightLaf());
    UIManager.put("ToolBar.focusableButtons", true);
    JToolBar toolbar = new JToolBar();
    JButton hideMe = new JButton("click me");
    hideMe.addActionListener(a -> hideMe.setVisible(false));
    toolbar.add(hideMe);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.add(toolbar);
    frame.pack();
    frame.setVisible(true);
  }

The problem seems to be, that com.formdev.flatlaf.ui.FlatToolBarUI.FlatToolBarFocusTraversalPolicy.getFirstComponent(Container) and com.formdev.flatlaf.ui.FlatToolBarUI.FlatToolBarFocusTraversalPolicy.getLastComponent(Container) both deliver the most recently focused component, even if this one is not visible so that the while loop in com.formdev.flatlaf.ui.FlatToolBarUI.FlatToolBarFocusTraversalPolicy.getComponentAfter(Container, Component) is stuck getting always the same component.

DevCharly commented 1 month ago

Thanks for reporting and your analysis. You're right 👍

fixed in latest 3.6-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots