views:

31

answers:

1

I have a Java program that I wrote that changes whether or not a JFrame is resizable depending on application state. In Windows this works great, when it is resizable the maximize button is enabled when it's not the button is disabled. However, on my Mac when I change resizable back to true the zoom button does not become enabled but the window DOES become resizable - the resize grabber shows.

Unfortunately, I haven't been able to replicate this behavior in a simple application. Only in my complex app does this appear. So I'm wondering other than the resizable state of a JFrame what affects if the zoom button is enabled?

+1  A: 

Here's a simple example that shows the expected behavior on Mac OS X; you might compare it to what you're doing for reference.

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToggleButton;

public class FrameTest extends JPanel implements Runnable {

    private JFrame f;
    private boolean test;

    public static void main(String[] args) {
        EventQueue.invokeLater(new FrameTest());
    }

    @Override
    public void run() {
        f = new JFrame("Test");
        test = f.isResizable();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(this);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

    public FrameTest() {
        this.add(new JToggleButton(new AbstractAction("Test") {

            @Override
            public void actionPerformed(ActionEvent e) {
                test = !test;
                f.setResizable(test);
            }
        }));
    }
}
trashgod
See I know I'm setting resizable correctly. 'cause the window itself IS resizable the zoom button just isn't enabled. It's rather aggravating...
Argothian
@Argothian: Does my example work correctly on your platform/version combination?
trashgod
@trashgod, yep works great. It's something funky that I'm doing in my app somewhere. I was hoping someone knew what would could affect the zoom button other than the resizable state because that's all I thought would affect it.
Argothian
@Argothian: Are you using `setUndecorated()` or `setDefaultLookAndFeelDecorated()`? It's not too hard to get the grow icon into the weeds that way.
trashgod
@trashgod: Nope.
Argothian
@Argothian: I've seen EDT violations damage the decorations' update region; it's something to check.
trashgod
@trashgod: Thanks for all your help. I still wasn't able to figure out the problem. I wasn't able to find any EDT violations (using the AspectJ method found here: http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html). If you have any other idea that'd be great! Otherwise for now I'm just recreating the JFrame when I need to re-enable the button. Not ideal, but it works and it doesn't get triggered too often.
Argothian
@Argothian: You might try `setVisible(false); setResizable(true); setVisible(true)`.
trashgod
@trashgod: That was one of the first things I tried to no avail.
Argothian