import javax.swing.*;
import java.awt.*;
public class TEST {
public static void main(String[] args) {
new Window();
}
static class Window extends JFrame {
Window() {
setSize(300, 250);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
ImageIcon icon = new ImageIcon("icon.jpg");
setIconImage(icon.getImage());
getContentPane().add(new JLabel(icon));
setLocationRelativeTo(null);
setVisible(true);
}
}
}
There is such a code why the image is not shown in the window and why the window icon is not placed. icon.jpg has a size of 32x32 pixels and is in src with the rest of the files (I use intellij idea). The result of executing the code is an empty window with a standard icon.
DenisJNewb
Level 11
GO TO FULL VERSION