Remove “X” button in Swing JDialog

前端 未结 6 881
时光说笑
时光说笑 2020-12-08 18:18

Is there a way to remove the close button (\"X\") from the JDialog title bar?

6条回答
  •  半阙折子戏
    2020-12-08 18:56

    As of Java 1.7 (AKA Dolphin or Java 7), you can not disable or remove the close button on a Window. You can remove/disable the maximize button with frame.setResizable(false) and you can remove the minimize and maximize buttons by using a java.awt.Dialog or a class that extends it, such as javax.swing.JDialog. You can remove the title bar, borders, and buttons with frame.setUndecorated(true), and you can have full control over the visibility of all buttons in the title bar (while losing some cross-platform compatibility and OS integration) with frame.setDefaultLookAndFeelDecorated(true) (assuming it's a JFrame or JDialog). This is all the control I see possible with the current JDK.

提交回复
热议问题