JFrame大小,调整大小,全屏

时间:2015-09-29 20:23:06

标签: java swing resize jframe fullscreen

我的问题有3个部分。

  1. 我想知道,如何将JFrame窗口设置为可调整大小,但不能在最小尺寸下进行,因此用户无法使其小于最小尺寸。
  2. 我想知道,如何将JFrame窗口设置为可调整大小,但即使用户正在调整大小,仍然保持宽高比(16:9)。
  3. 我想知道,如果他点击一个按钮后我怎么能让程序变成全屏,所以没有边框,像游戏一样运行(如果有任何具体问题我怎么能还原它安全地)。
  4. 感谢您的帮助和耐心,因为我的英语不完美而且不完善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 个答案:

答案 0 :(得分:2)

  1. 设置框架的最小尺寸(setMinimumSize)
  2. 更难,因为事后你会收到尺寸变化的通知,所以你总是在变化时对抗系统(然后你会遇到生成尺寸变化事件的人的问题)。最好根据帧内的可用空间集中精力保持帧内容的比例(VLC就是一个很好的例子)。
  3. Full screen exclusive mode
相关问题