How to make a JFrame really fullscreen?

后端 未结 5 2101
深忆病人
深忆病人 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:37

    An example:

    import java.awt.FlowLayout;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    
    
    
    public class FullScreenJFrame extends JFrame{
    
        private GraphicsDevice vc;
    
        public FullScreenJFrame(){
         super();
    
         GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
         vc= e.getDefaultScreenDevice();
    
    
    
         JButton b = new JButton("exit");
         b.addActionListener(
                 new ActionListener(){
                     public void actionPerformed(ActionEvent arg0) { 
                         dispose();
                         System.exit(0);
    
                     }
                 }
                 );
         this.setLayout(new FlowLayout());
         this.add(b);
         setFullScreen(this);
     }
    
     public void setFullScreen(JFrame f){
    
         f.setUndecorated(true);
         f.setResizable(false);
         vc.setFullScreenWindow(f);
    
    
     }
    
     public static void main(String[] args){
         new FullScreenJFrame();
     }
    
    }
    

提交回复
热议问题