如何在Java中隐藏JFrame窗口上默认的最小化/最大化和关闭按钮?

发布于 2025-01-01 15:50:46 字数 102 浏览 3 评论 0 原文

我想知道是否可以创建一个没有默认最大化/最小化(-)和关闭(x)按钮的 JFrame 窗口!我在每个框架上添加了自定义按钮,这样用户就不必弄乱窗口右上角的默认按钮!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

世俗缘 2025-01-08 15:50:46

您可以使用 JWindow 因为默认情况下是 un_decorated ,但您可以 setUndecorated() 对于 JFrame/JDialog

另一种方法是

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

another ways are

一张白纸 2025-01-08 15:50:46

使用 JFrame.setDefaultLookAndFeelDecolated。这可能不是你真正需要的东西,但医生说,

提供关于新创建的 JFrame 是否应该具有的提示
他们的窗口装饰(例如边框、用于关闭窗口的小部件)
窗口、标题...)由当前外观提供。

试试这个代码:

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);

这将删除整个标题栏。另请查看此线程

否则使用 JWindows

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.

与酒说心事 2025-01-08 15:50:46
JFrame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);

将使“X”按钮不起作用。这对我有用。

JFrame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);

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

清君侧 2025-01-08 15:50:46

如果您使用的是 Netbean,则只需在属性中取消选择可调整大小选项即可。
它只会禁用最小化/最大化按钮。

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

半枫 2025-01-08 15:50:46
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文