【发布时间】:2015-09-29 20:23:05
【问题描述】:
我的问题有 3 个部分。
- 我想知道,如何将
JFrame窗口设置为可调整大小,但不能低于最小尺寸,因此用户不能使其小于最小尺寸。 - 我想知道,如何将
JFrame窗口设置为可调整大小,但即使用户调整其大小仍保持纵横比 (16:9)。 - 我想知道,我怎样才能让程序在他点击一个按钮后变成真正的全屏,这样就没有边框并且像游戏或其他东西一样运行(如果有任何具体问题我该如何恢复它安全)。
感谢您的帮助和耐心为我不完美的英语和不完美的 Java 知识。
提供的答案很有用,并且回答了我的部分问题,但对我来说大部分仍然是空白的。
部分代码:
private void createDisplay() {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
frame = new JFrame(title); //setting the title of the window
frame.setSize(width, height); //setting the width and height of the window
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //make sure program closes down properly
frame.setResizable(true);
frame.setLocationRelativeTo(null); //the window will apparel on the center
frame.setVisible(true);
frame.setIconImage(Assets.ImageMap.get("icon"));
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(width, height));
canvas.setMaximumSize(new Dimension(width, height));
canvas.setMinimumSize(new Dimension(gd.getDisplayMode().getWidth() / 2, gd.getDisplayMode().getHeight() / 2));
canvas.setFocusable(false);
frame.add(canvas);
frame.pack(); //resize the window a little bit so able to see all of canvas
}
【问题讨论】:
-
JFrame in full screen Java 的可能重复项
-
请提供您尝试过的代码。
标签: java swing resize jframe fullscreen