我的问题有三部分。
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
}发布于 2015-09-29 20:32:56
https://stackoverflow.com/questions/32853110
复制相似问题