Reputation: 14697
I've seen many answers for this question when it's a JFrame
, but none for JPanel
, and all that I've tried didn't work.
So basically I've written this simple class/app that extends JPanel
, and all is working fine. Now I'd like to change the Default Icon.
Any ideas?
Upvotes: 1
Views: 2025
Reputation: 7943
Just as guys are saying here in comments please reconsider what you are trying to do. The only option to change an icon is to set it for the frame in which the panel is child, since the icon is a part/belongs to the frame.
If you want setting of the icon to be a functionality of a panel then in addNotify() method, which is called when a component receives a parent, look through the panel's parent and it parent and so on until you will reach the frame and set the icon for it.
Sample showing a number of parent you must go through to get to frame if a panel is its content pane.
JPanel p = new JPanel();
JFrame f = new JFrame();
f.setContentPane(p);
System.out.println(SwingUtilities.windowForComponent(p));
Upvotes: 2