簡體   English   中英

JFrame大小,調整大小,全屏

[英]JFrame size, resize, fullscreen

我的問題分為三個部分。

  1. 我想知道,如何將JFrame窗口設置為可調整大小,但不能設置為最小大小,因此用戶無法將其設置為小於最小大小。
  2. 我想知道,如何將JFrame窗口設置為可調整大小,但是即使用戶正在調整它的大小,仍要保持寬高比(16:9)。
  3. 我想知道,在他單擊按鈕后如何使程序真正變成全屏顯示,這樣就沒有邊框了,並且像游戲之類的東西一樣運行(並且如果有任何特定的問題,我該如何安全地還原它)。

感謝您的幫助和耐心,因為我的英語水平還不太好,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
}
  1. 設置框架的最小尺寸(setMinimumSize)
  2. 更加困難,因為事后會通知您大小更改,因此您將始終在系統更改時與系統進行斗爭(然后您會遇到由誰生成大小更改事件的問題)。 最好根據框架內的可用空間集中於保持框架內容的比率(VLC是一個很好的例子)
  3. 全屏獨占模式

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM