How to hide the default minimize/maximize and close buttons on JFrame window in Java?

泄露秘密 提交于 2019-12-30 04:46:11

问题


I would like to know if it is possible to create a JFrame window which has no default maximize/minimize(-) and close(x) buttons! I have added custom buttons on each frame so that the user does not have to mess around with the default ones on the top right corner of the window!


回答1:


You can use JWindow because is by default un_decorated, but you can setUndecorated() for JFrame/JDialog

another ways are

  • implements WindowListener

  • setDefaultCloseOperations




回答2:


Use JFrame.setDefaultLookAndFeelDecorated. It may not be the exact thing you need but doc says,

Provides a hint as to whether or not newly created JFrames should have their Window decorations (such as borders, widgets to close the window, title...) provided by the current look and feel.

Try this code:

JFrame frame = new JFrame("Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(100, 100);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
frame.setVisible(true);

This will remove the entire titlebar. Also take a look at this thread.

Otherwise use JWindows.




回答3:


frame.setUndecorated(true); frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);




回答4:


JFrame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);

Will make the 'X' button no functioning. It's works for me.




回答5:


If you are using Netbean then just unselect the resizable option in properties. It will only disable Minimize/Maximize Button.



来源:https://stackoverflow.com/questions/9101418/how-to-hide-the-default-minimize-maximize-and-close-buttons-on-jframe-window-in

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