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

后端 未结 5 644
青春惊慌失措
青春惊慌失措 2021-01-02 22:35

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

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-02 23:05

    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.

提交回复
热议问题