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

StackOverflowError #14

Closed
lbalazscs opened this issue Oct 19, 2019 · 1 comment
Closed

StackOverflowError #14

lbalazscs opened this issue Oct 19, 2019 · 1 comment

Comments

@lbalazscs
Copy link

I am using version 0.13 from Maven. The following code throws StackOverflowError apparently because of an infinite loop. As I explained in the comments, this can be reproduced only if pack is not called.

import com.formdev.flatlaf.FlatDarculaLaf;
import com.formdev.flatlaf.FlatIntelliJLaf;

import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Window;

public class UpdateComponentTreeProblem {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(UpdateComponentTreeProblem::runOnEDT);
    }

    private static void runOnEDT() {
        setLaf(new FlatDarculaLaf());

        JFrame f = new JFrame("Test");
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.setLayout(new BorderLayout());

        JComboBox<String> themeChooser = new JComboBox<>(new String[]{"Light", "Dark"});
        themeChooser.setName("themeChooser");
        themeChooser.setSelectedItem("Dark");

        themeChooser.addActionListener(e -> {
            String themeName = (String) themeChooser.getSelectedItem();
            if(themeName.equals("Light")) {
                setLaf(new FlatIntelliJLaf());
            }
        });
        f.add(themeChooser, BorderLayout.NORTH);
        f.add(new JLabel("Change the theme to \"Light\"!"));

        // In order to reproduce the problem,
        // it is crucial NOT to call pack().
        // In a real app the window size could be read
        // from the saved preferences and set manually.
//        f.pack();
        f.setSize(600, 400);

        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

    private static void setLaf(LookAndFeel laf) {
        try {
            UIManager.setLookAndFeel(laf);
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        Window[] windows = Window.getWindows();
        for (Window window : windows) {
            SwingUtilities.updateComponentTreeUI(window);
        }
    }
}
@JFormDesigner
Copy link
Owner

thanks, fixed in 0.14

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