2015-09-29 260 views
0

我的问题有3个部分。JFrame大小,调整大小,全屏

  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

全屏的[JFrame的可能重复Java](http://stackoverflow.com/questions/11570356/jframe-in-full-screen-java) –

+0

请提供您尝试过的代码。 – ashiquzzaman33

回答

2
  1. 设置帧的最小尺寸(了setMinimumSize)
  2. 是比较困难的,因为你得到通知的事实后的尺寸变化的,所以你会总是在系统发生变化时与系统进行对抗(然后遇到问题的原因是谁生成了尺寸变化事件)。这可能是更好的专注于保持的基础上,框架内的可用空间框架的内容的比例(VLC就是一个很好的例子)
  3. Full screen exclusive mode