gpt4 book ai didi

java - 如何为所有 Java Swing 窗口设置默认图标?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:40:55 25 4
gpt4 key购买 nike

如何为所有 Java Swing 窗口设置默认图标?

否则我必须为我创建的每个框架设置图标。

你有什么建议?也接受简单的黑客攻击。

非常感谢

更新:最好是您建议的方法可以保持现有的框架创建代码不变。谢谢

最佳答案

创建一个 扩展 JFrame 的抽象类

在构造函数中设置你的图标。

创建继承新抽象类的子类并在构造函数中调用super

public abstract class MainFrame extends JFrame {
protected MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}

public class ChildFrame extends MainFrame {
public ChildFrame() {
super();
}
}

你也可以只从你的新类创建对象

public class MainFrame extends JFrame {
public MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}

public class Frame {

private MainFrame mainframe = new MainFrame();

public Frame() {
super();
}
}

关于java - 如何为所有 Java Swing 窗口设置默认图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3183259/

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