JavaRush /Java Blog /Random EN /Java ImageIcon and crooked hands
DenisJNewb
Level 11

Java ImageIcon and crooked hands

Published in the Random EN group
Java ImageIcon and crooked hands - 1
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.
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION