Connecting Tech Pros Worldwide Forums | Help | Site Map

Help me try finding the error

Newbie
 
Join Date: Jul 2008
Posts: 11
#1: Oct 9 '08
Hello Friends
The code below has no error at compile time.
But while executing, it does not show the icon at the left hand top corner of the frame, where a java cup icon is originally shown.
I want to replace it with my icon.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.util.*;
  5.  
  6. class Error1
  7. {
  8.  
  9. public JPanel contentPane()
  10. {
  11. JPanel panel=new JPanel();
  12. JLabel label=new JLabel("This is a frame with its own Icon.");
  13. panel.add(label);
  14.  
  15.  
  16. return panel;
  17.  
  18. }
  19.  
  20. private static void createGui() 
  21.    {
  22.  
  23.  
  24.        JFrame frame=new JFrame("Error");
  25.        frame.setDefaultLookAndFeelDecorated(false);
  26.        Error1 obj=new Error1();
  27.        frame.setContentPane(obj.contentPane());
  28.        frame.setVisible(true);
  29.        frame.setSize(new Dimension(650,100));
  30.        frame.setResizable ( false );
  31.        frame.setLocation(50,50);
  32.  
  33.       // frame.setIconImage(getFDImage());
  34.        Image icon = Toolkit.getDefaultToolkit().getImage("D:\\error.bmp");
  35.        frame.setIconImage(icon);
  36.     }    
  37.     /*protected static Image getFDImage() 
  38.     {
  39.         java.net.URL imgURL = Error.class.getResource("D:\\error.bmp");
  40.         if (imgURL != null)
  41.         {
  42.             return new ImageIcon(imgURL).getImage();
  43.         } else 
  44.         {
  45.             return null;
  46.         }
  47.     }*/
  48.     public static void main(String args[]) 
  49.     {
  50.            SwingUtilities.invokeLater(new Runnable() {public void run() {createGui(); }});
  51.     }
  52. }

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Oct 9 '08

re: Help me try finding the error


You can only use .gif, .jpeg, .jpg or .png files; a .bmp file isn't recognized. Also
see the Toolkit.getImage() API documentation.

kind regards,

Jos
Reply