1

the icon image is not showing in the frame plus I use NetBeans

static void display_frame1() {
    JFrame frame = new JFrame();//create and name frame
    frame.setTitle("U'sh Bookstore"); //set title
    frame.setSize(420, 420); //set frame size
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);// frame cant be resized
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //exit frame
    frame.getContentPane().setBackground(Color.pink);
    

    ImageIcon image = new ImageIcon("icon.jpg");//create an image icon
    frame.setIconImage(image.getImage());//change icon frame --> IT IS NOT 
    frame.getContentPane().setBackground(Color.pink);
    
    frame.setVisible(true);//make frame visible
}
Frakcool
  • 10,915
  • 9
  • 50
  • 89
  • 1
    Are you sure your program is finding the path to the icon? Swing applications will become embedded-resources when packaged as a JAR, so it's wise to treat them as they already were, see [this answer](https://stackoverflow.com/a/42170674/2180785) as an example of how to load those images. – Frakcool Mar 30 '21 at 22:51
  • 1
    Application resources will become embedded resources by the time of deployment, so it is wise to start accessing them as if they were, right now. An [tag:embedded-resource] must be accessed by URL rather than file. See the [info. page for embedded resource](http://stackoverflow.com/tags/embedded-resource/info) for how to form the URL. Also, load the image using `ImageIO` which will produce helpful output if the resource is not found. – Andrew Thompson Mar 30 '21 at 23:58

0 Answers0