How to maximize a JFrame through code?

好久不见. 提交于 2019-11-27 14:18:22

问题


How to maximize a JFrame through code?


回答1:


Try this:

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



回答2:


this works perfectly till java 7

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



回答3:


Yea the Toolkit solution ignores the windows task bar and uses the full screen which is not what you want.

For an immediate maximise of your form just add this in the JFrame constructor after the InitiateComponents() call.

this.setExtendedState(JFrame.MAXIMIZED_BOTH);

The class extends JFrame of course:

public class MyForm extends javax.swing.JFrame



回答4:


setExtendedState(JFrame.MAXIMIZED_BOTH); is not working is 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);



回答5:


for similar problems with: http://bugs.sun.com/view_bug.do?bug_id=7177173

An issue on jdk7. Try to call .setExtendedState() not directly after .setVisable()



来源:https://stackoverflow.com/questions/5258207/how-to-maximize-a-jframe-through-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!