tags:

views:

49

answers:

1

Hi,

This is not a huge problem but I am wondering if there is a solution. In the example below a window opens with a button and if you press that button another window opens, in Windows 7 it does a little effect when it opens. When you close the new window it does another effect for closing. If I press the button again it just pops up without the effect. Is there a way to fix that so that the effect always works without re-creating the frame?

import javax.swing.*;
import java.awt.event.*;

public class asd
{
    private static JFrame frame2;
    public static void main (String[] args)
    {
        frame2 = new JFrame();
        frame2.setSize (500, 500);

        JButton button = new JButton ("Button");
        button.addActionListener (new ActionListener() {
            @Override public void actionPerformed (ActionEvent e) {
                frame2.setVisible (true); } });

        JFrame frame = new JFrame();
        frame.add (button); frame.setSize (500, 500);
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.setVisible (true);
    }
}
A: 

I don't have a Win7 box so this is just another guess.

qmega's comment is probably the reason, so the answer could be calling dispose() then pack(); setVisible(true) in your action handler.

Ref Window#dispose javadoc.

Geoffrey Zheng
Yes but I don't want to run dispose, that will just destroy my window forcing me to remake it. I don't want to spend more processing power. Especially for very complex windows.
Dave
I'm not sure about this: if you swap out your content pane (and other layers with your own stuff), dispose window, add your stuff back, would the resources that your stuff use be reused?Anyway if the window open/close effect is new in Win7, it's very unlikely that you can somehow access it directly in Swing, or Java even knows about it, given JDK's recent pace.
Geoffrey Zheng