开发者

What affects the enabled status of the zoom button on a JFrame for Mac?

开发者 https://www.devze.com 2023-01-10 03:02 出处:网络
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 wh

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.

开发者_如何学C

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?


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

精彩评论

暂无评论...
验证码 换一张
取 消