How to make a JFrame really fullscreen?

后端 未结 5 2110
深忆病人
深忆病人 2020-12-14 17:46

In my Java application I try to make a JFrame really fullscreen by using this code:

public class MainFrame extends JFrame {

    private static final long se         


        
5条回答
  •  孤街浪徒
    2020-12-14 18:10

    private Dimension screenSize; /* class level vars */
    private swidth , sheight;
    
    /*In GUI creating method:put this code: */
    screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    sheight = screenSize.height;
    swidth = screenSize.width;
    setBounds(0, 0, swidth, sheight-40);
    

    NB: using swidth, sheight vars give you the liberty to further adjust.
    Best way is to use int vars in place of - 40 e.g sheight/swidth - margin etc.
    Here margin should come from parameter table. Getting full control of situation.
    Direct usage also possible as: setBounds(0,0,screenSize.width, screenSize.height);

提交回复
热议问题