Search code examples
swingnetbeansiconsgui-builder

Setting an icon for a jFrame in Netbeans swing gui builder


I've been trying to set up a window in Netbean's GUI builder, without success. I've tried accessing the JFrame, from my main class as:

public void run(){

    JFrame frame = new JFrame("Title of Frame");
    frame.setIconImage(Toolkit.getDefaultToolkit().getImage("org/icon.png"));

}

Which creates a new frame apart from my main window with my icon.png. I'd like to know if there is some way to gain access to the JFrame that contains the rest of my UI elements, and set that icon.

I've also tried new SearchAppUI().setIconImage(null); which doesn't do anything of note.

Setting the icon directly:

JFrame.setIconImage("org/icon.png"); 

gives me the error, non-static method setIconImage(java.awt.Image) cannot be referenced from a static context.

Is there any way to set the main JFrame's icon from either Netbean's swing desinger preview, or from my run() method?


Solution

  • NVM, I found a solution on: http://www.youtube.com/watch?v=o_35iro4b7M

    Describing how to set the icon and title of a jFrame. Basically, it requires the libraries

    import javax.swing.JFrame;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.awt.Image;
    import javax.imageio.ImageIO;
    

    I pretty much wanted to stick with using Netbean's guibuilder for now, at least for prototyping.