gpt4 book ai didi

java - 防止 JFrame 显示任何图标

转载 作者:行者123 更新时间:2023-12-01 17:05:32 25 4
gpt4 key购买 nike

我不希望我的 jframe 在任务栏中显示任何图标。基本上,如果我们不指定任何 IconImage ,那么它会显示默认图标。但在我的程序中我不希望显示任何图标。

 setUndecorated(true);
setSize(208, 58);
setImageIcon(null); // same result

如果我使用透明图像作为图标,即使这样系统也会显示一个半透明的矩形图标。

enter image description here

我的问题很简单。我认为我不需要为此提供任何编码。如果有任何方法可以做到这一点,请告诉我。
实现此目的的一种方法是使用 JWindowWindow,但使用它有很多缺点,我不想这样做。

最佳答案

一种可能的解决方案:不显示 JFrame,而是显示 JDialog。请注意,您放入 JFrame 的 contentPane 中的任何复杂 GUI 都可以放入 JDialog 中,这是避免创建 JFrame 子类的应用程序的另一个原因。例如:

import java.awt.Dimension;
import javax.swing.*;

public class TestJDialog {
private static void createAndShowGui() {
JDialog dialog = new JDialog((JFrame)null, "Test JDialog", true);

// Using rigid area just to give the dialog size, but you
// could put any complex GUI in a JPanel in here
dialog.getContentPane().add(Box.createRigidArea(new Dimension(400, 400)));
dialog.pack();
dialog.setLocationByPlatform(true);
dialog.setVisible(true);
System.exit(0); // to end Swing event thread
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}

缺点是您会丢失窗口右上角的最小化和恢复按钮,但无论如何您都不应该拥有这些按钮,因为您没有用于恢复 GUI 的关联图标。

关于java - 防止 JFrame 显示任何图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25734400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com