How to call setUndecorated() after a frame is made visible?

前端 未结 7 1754
醉梦人生
醉梦人生 2020-11-30 10:52

In my Swing application, I want the ability to switch between decorated and undecorated without recreating the entire frame. However, the API doesn\'t let me call setU

相关标签:
7条回答
  • 2020-11-30 11:49

    Here is a code in how to make ALT + Enter enters Full Screen without the bar mode and Minimize with showing the Title bar and the Start bar:

    public class myTest extends JFrame{
     //Your codes...
         //if "ALT" key on hold and "Enter" key pressed with it
         if (evt.isAltDown() && evt.getKeyCode() == evt.VK_ENTER) {    
             //if the JFrame has Title bar
             if (isUndecorated()) {
                 //this will dispose your JFrame
                 dispose();
                 //here to set it with no Title bar
                 setUndecorated(false);
                 pack();
                 setLocationRelativeTo(null);
                 //as you dispose your JFrame, you have to remake it Visible..
                 setVisible(true);
              } else {
                 dispose();
                 setUndecorated(true);
                 setExtendedState(MAXIMIZED_BOTH);
                 setVisible(true);
            }
        }
    //your codes
    }
    
    0 讨论(0)
提交回复
热议问题