[英]JFrame size, resize, fullscreen
我的問題分為三個部分。
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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.