tags:

views:

45

answers:

1

How to set the default icon for all Java Swing windows?

Otherwise i have to set icons for every frame i created.

What's your suggestions? Simple hackings are also accepted.

many thx

Update: Best if the method you suggested can leave existing frame-creation codes untouched. thx

+1  A: 

Create an Abstact class that extends JFrame

In the constructor set your icon.

create child class that extends your new Abstract Class and call super in 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 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();
    }
}
Michael B.
+1 Also I believe all JDialogs inherit the icon from their parent window, so just need to worry about the JFrames/JWindows.
krock
That's still an alternative method to set icon for every frame created. The biggest drawback is that it's not friendly with existing codes.
dex