Leak on default buttons #75

Closed
Gotusso opened this Issue May 10, 2012 · 0 comments

Comments

Projects
None yet
2 participants

Gotusso commented May 10, 2012

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();
            }
        });
    }
}

shemnon closed this in 16a14b4 May 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment