When creating an AWT Frame
in a Java program running on MacOS, the maximize button in the frame's title bar maximises the window:
public static void main(String args[]) {
new Frame();
}
When I create a Swing JFrame
instance instead, the same button toggles the window into fullscreen mode, which is the standard behaviour on MacOS. The button even looks different visually when I hover over it:
public static void main(String args[]) {
new JFrame();
}
Is there any way how I can replicate JFrame's "maximize to fullscreen" behaviour with AWT's Frame? I scanned the code of the entire JFrame class and wasn't able to identify any logic that would toggle the Frame's behaviour in such a way.
Try this code:
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
public class MyFrame extends Frame {
MyFrame() {
for (Window w : Window.getWindows()) {
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().setFullScreenWindow(w);
}
}
public static void main(String args[]) {
MyFrame f = new MyFrame();
f.setVisible(true);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.