Skip to content

Instantly share code, notes, and snippets.

@benjjo
Created April 27, 2020 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjjo/4eb4165b113c3211dc903dca58e5e0ba to your computer and use it in GitHub Desktop.
Save benjjo/4eb4165b113c3211dc903dca58e5e0ba to your computer and use it in GitHub Desktop.
package org.kodejava.example.swing;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
public class FrameIconExample extends JFrame {
public static void main(String[] args) {
FrameIconExample frame = new FrameIconExample();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// Set the window size and its title
frame.setSize(new Dimension(250, 250));
frame.setTitle("Frame Icon Example");
// Read the image that will be used as the application icon.
// Using "/" in front of the image file name will locate the
// image at the root folder of our application. If you don't
// use a "/" then the image file should be on the same folder
// with your class file.
try {
URL resource = frame.getClass().getResource("/logo.png");
BufferedImage image = ImageIO.read(resource);
frame.setIconImage(image);
} catch (IOException e) {
e.printStackTrace();
}
// Display the form
frame.setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment