简体   繁体   English

如何通过代码最大化JFrame?

[英]How to maximize a JFrame through code?

如何通过代码最大化JFrame?

试试这个:

f.setExtendedState( f.getExtendedState()|JFrame.MAXIMIZED_BOTH );

this works perfectly till java 7 这完美地工作到java 7

public class TEST
{
    public static void main(String args[])
    {
        JFrame jf= new JFrame();
        jf.setVisible(true);
        jf.setExtendedState(JFrame.MAXIMIZED_BOTH);
        }
}

Yea the Toolkit solution ignores the windows task bar and uses the full screen which is not what you want. 是的工具包解决方案忽略了Windows任务栏并使用了不是你想要的全屏。

For an immediate maximise of your form just add this in the JFrame constructor after the InitiateComponents() call. 为了立即最大化您的表单,只需在InitiateComponents()调用后在JFrame构造函数中添加它。

this.setExtendedState(JFrame.MAXIMIZED_BOTH);

The class extends JFrame of course: 该课程当然扩展了JFrame

public class MyForm extends javax.swing.JFrame

setExtendedState(JFrame.MAXIMIZED_BOTH); setExtendedState(JFrame.MAXIMIZED_BOTH); is not working is java 7 不工作是java 7

You can try this code it works. 您可以尝试使用此代码。

     Toolkit tk = Toolkit.getDefaultToolkit();  
     int xSize = ((int) tk.getScreenSize().getWidth());  
     int ySize = ((int) tk.getScreenSize().getHeight());  
     setSize(xSize,ySize);

for similar problems with: http://bugs.sun.com/view_bug.do?bug_id=7177173 对于类似的问题: http//bugs.sun.com/view_bug.do?video_id = 7177173

An issue on jdk7. 关于jdk7的问题。 Try to call .setExtendedState() not directly after .setVisable() 尝试在.setVisable()之后不直接调用.setExtendedState()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM