How to change java icon in a JFrame

后端 未结 5 1047
渐次进展
渐次进展 2020-12-31 11:54

Ok so I\'ve been researching this one quiet a bit. I am fairly new to java but thought that this one would be easy. Ive tried just about every way that has been answered on

5条回答
  •  孤城傲影
    2020-12-31 12:49

    For example in a NetBeans project, create a resources folder in the src folder.

    Put your images (jpg, ...) in there.

    Whether you use ImageIO or Toolkit (including getResource), you must include a leading / in your path to the image file:

    Image image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/resources/agfa_icon.jpg"));
    setIconImage(image);
    

    If this code is inside your JFrame class, the image is added to the frame as an icon in your title bar.

提交回复
热议问题