Insubstantial / insubstantial

Swing look-and-feel library and assorted widgets
193 stars 58 forks source link

Leak on default buttons #75

Closed Gotusso closed 12 years ago

Gotusso commented 12 years ago

When setting a default button on a JDialog with substance LAF, the dialog is never collected. Without the LAF everything is OK. I think that the animation of the button is still running. Take as example the following snippet:


import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.lang.reflect.InvocationTargetException;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

import org.pushingpixels.substance.api.skin.SubstanceOfficeBlack2007LookAndFeel;

public class TridentLeakSnippet extends JFrame  {
    public static class LeakedDialog extends JDialog {
        private final byte[] leakedContent = new byte[1024 * 1024 * 10];

        public LeakedDialog() {
            final JPanel root = new JPanel();
            final JButton button = new JButton("A default button");

            root.add(button);
            getContentPane().add(root);
            getRootPane().setDefaultButton(button);

            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        }
    }

    public TridentLeakSnippet() {
        final JPanel root = new JPanel();
        final JButton button = new JButton(new AbstractAction("Create a dialog") {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final JDialog dialog = new LeakedDialog();
                dialog.pack();
                dialog.setLocationRelativeTo(null);
                dialog.setVisible(true);
            }
        });

        root.add(button);
        getContentPane().add(root);

        initLAF();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new Dimension(200, 200));

        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    private void initLAF() {
        try {
            UIManager.setLookAndFeel(new SubstanceOfficeBlack2007LookAndFeel());
            SwingUtilities.updateComponentTreeUI(this);
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void main(final String[] args) throws InterruptedException, InvocationTargetException {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                new TridentLeakSnippet();
            }
        });
    }
}