How to set default icon for all Java Swing windows?

How to set default icon for all Java Swing windows?

Otherwise, I need to set icons for each frame created.

What are your suggestions? Simple hacks are also accepted.

many thanks

Update: it is best if the proposed method can leave the existing frame creation code indispensable. THX

+3
source share
1 answer

Create an Abstact class that extends JFrame

In the designer, set your icon.

create a child class that extends your new one Abstract Classand calls superin your constructor

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

You can also just create an object from your new class.

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();
    }
}
+1
source

Source: https://habr.com/ru/post/1753231/


All Articles