I could use some help regarding the setting of an icon on a JFrame. I have a Java 8 application that is typically used in both Windows and Linux environments. The application is composed of a number of "SFrames", which are a custom class that extends a JFrame and includes the setting of a custom icon for the frame. There is one main "SFrame" for the application, and then other "SFrames" are brought up as needed depending on the actions of the user. All "SFrames" have the same icon displayed.
In the past when running this application on both Windows and Linux the correct icon appeared on all "SFrames" (the main application "SFrame", and then all subsequent frames that were brought up). The execution environment for Linux was recently updated from an older version of Fedora (with the Mate desktop environment) to a recent version of Red Hat Enterprise Linux (also with the Mate desktop environment). In this new Linux environment the icon was not appearing on any of the "SFrames", either the main frame or any subsequent frames that appear.
I did see this Stackoverflow entry (JFrame icon not displaying in Ubuntu 12.04), and setting setDefaultLookAndFeelDecorated to "true" in the "SFrame" constructor does cause the icon to appear on subsequent SFrames that are brought up under Linux, but not the first frame. The first SFrame continues to have no icon on it, and appears very similar to the default appearance of other Mate windows. Later experimentation showed that it is always the first SFrame that is left at the default appearance with no icon, regardless of whether subsequent SFrames are called from the first SFrame (i.e., subsequent SFrames are like "children" of the first SFrame, as shown in the example below), or whether multiple SFrames are called sequentially (i.e., subsequent SFrames are like "younger siblings" of the first SFrame).
With the minimum reproducible example given below, the attached graphic shows the results on Windows and Linux. For Windows, both SFrames have an icon displayed, in this case the letter "A". These results are produced on Windows regardless of whether the call to setDefaultLookAndFeelDecorated is made or not. For Linux, the first SFrame is displayed with no icon, the second SFrame with an icon. If the call to setDefaultLookAndFeelDecorated is not made then neither SFrame has the icon on Linux.
Graphic: click here
import javax.swing.*;
class SFrame extends JFrame {
private static final ImageIcon image = new ImageIcon("icon.png");
public SFrame() {
setDefaultLookAndFeelDecorated(true);
if (image != null)
{
setIconImage(image.getImage());
}
}
}
class ChildFrame extends SFrame {
public ChildFrame() {
// Dimensions set so two windows do not overlap
setBounds(350, 100, 200, 400);
setTitle("CHILD");
}
}
public class MinimumExample extends SFrame {
private SFrame childFrame_;
public MinimumExample() {
// Dimensions set so two windows do not overlap
this.setBounds(100, 100, 200, 400);
this.setTitle("PARENT");
this.setVisible(true);
childFrame_ = new ChildFrame();
childFrame_.setVisible(true);
}
public static void main(String args[]) {
new MinimumExample();
}
}
Could somebody point me in the right direction for a fix? Thanks