简体   繁体   English

如何禁用JFrame中的最小化按钮?

[英]How to disable the minimize button in JFrame?

Can I disable the minimize button in JFrame? 我可以在JFrame中禁用最小化按钮吗?

I have already tried setUndecorated() and setResizable() but both did not work. 我已经尝试过setUndecorated()和setResizable(),但是都没有用。

I'm trying to add images to a panel at a random location (which works) but when the JFrame is minimized by clicking at the minimize button (not when frame minimizes by clicking the background window) images assemble at the top in a row. 我试图将图像添加到面板上的任意位置(有效),但是当通过单击“ 最小化”按钮来最小化JFrame时(而不是通过单击背景窗口来最小化框架时),图像会排在顶部。

Can someone help? 有人可以帮忙吗?

Thanks! 谢谢!

If you also want to disable the maximize button then you can use a JDialog instead of a JFrame... as far as I know you cannot disable the minimize button in a JFrame. 如果您还想禁用最大化按钮,则可以使用JDialog代替JFrame ...据我所知,您不能禁用JFrame中的最小化按钮。 JDialog only has a close button. JDialog只有一个关闭按钮。 Hope this helps 希望这可以帮助

im trying to add imags to a panel at a random location which im able to do) bt wen frame is minimized by clicking at the minimize button (not wen frame minimizes by clicking at the background window) images assemble at the top in a row. 我试图在随机位置上将图像添加到面板上,这是不可能的)bt wen框架是通过单击最小化按钮(不是wen框架是通过单击背景窗口来最小化)来最小化的,图像在顶部连续排列。

Well, it sounds like you are adding labels to a panel and using the setLocation() method to position the labels. 好吧,这听起来像是在向面板添加标签并使用setLocation()方法放置标签。

The problem is that by default a JPanel uses a FlowLayout so whenever you do anything to the frame like minimize, maximize, iconify or resize the frame the layout manger is invoked and the labels are arranged according the the rules of the layout manager. 问题在于,默认情况下,JPanel使用FlowLayout,因此无论何时对框架执行任何操作(如最小化,最大化,图标化或调整框架大小),都会调用布局管理器,并根据布局管理器的规则来排列标签。

If your requirement is to have random positioning, then you need to use a "null layout". 如果您的要求是随机放置,则需要使用“空布局”。

Read the section from the Swing tutorial that explains how Absolute Positioning works for more information and a working example. 阅读Swing教程中的部分,该部分解释了绝对定位的工作原理,以获取更多信息和一个可行的示例。

使用JDialog代替JFrame,它的顶部只有Close按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM