0

Everytime I ran my project with setIcon on the JFrame, the Icon shows up but everything else inside of the JFrame disappear. When I resize the window everything appears again...

    java.net.URL iconURL = getClass().getResource("/img/steam.png");
    // iconURL is null when not found
    ImageIcon icon = new ImageIcon(iconURL);
    f.setIconImage(icon.getImage());
    f.setVisible(true);
    f.setSize(250,150);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

I've already tried with other types of code, nothing works properly, why maaan??

  • How is this an icon error? It sounds like the problem is with the layout of your JFrame’s contents, and has nothing to do with the icon. – VGR Apr 06 '17 at 20:44
  • Call `setVisible` last, after you have established the UI or call `revalidate` and `repaint` on the container to trigger a layout and paint cycle – MadProgrammer Apr 06 '17 at 20:47
  • I'd also recommend using [`setIconImages`](https://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setIconImages(java.util.List)) instead to provide a more flexible solution across multiple platforms – MadProgrammer Apr 06 '17 at 20:50

0 Answers0