By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,761 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,761 IT Pros & Developers. It's quick & easy.

Help me try finding the error

P: 14
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. }
Oct 9 '08 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
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
Oct 9 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.