开发者

Both maximizing and preventing resizing on a JFrame?

I am making a game, so I want the JFrame to start maximized, but I also don't want users resizing the game, as it would screw up the graphics. I am wondering how to do both at the same time?

Right now, I can use J开发者_如何学PythonFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) to maximize, but as soon as I do JFrame.setResizeable(false), I can't use setExtendedState() to maximize it anymore.

I realize I can just maximize it, store the width and height, then use that, but if possible I would prefer for the window to actually look like it is maximized. The title bar changes when it is maximized versus when it is just sized to fill the screen, if anyone knows what I am talking about.


This works for me:

frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
frame.setResizable(false);


If you are using JSR296 this is the way it works inside the singleton Application class:

    JFrame main = view.getFrame();
    main.setExtendedState(JFrame.MAXIMIZED_BOTH);
    main.pack();
    show(view);
    main.setResizable(false);

Without the pack() operation the window is not maximized. This was tested using Linux and Java 6.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜