Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to set label icon

 
Mahendra Kariya
Greenhorn
Posts: 26
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to initialise an applet when I set icon to a JLabel. The same code is running fine for JFrame. When I run the following code, it says "Applet not initialised". The image is in the same folder as that of the class file.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Per the applet tutorials, Sun recommends that Swing components be initialized on the EDT (Event Dispatch Thread) and inside an invokeAndWait method to allow time for the applet to initialize. So if you do this, does it work? e.g.,


Also, you may need to be careful with getting the ImageIcon this way if you plan to put the applet into a Jar.
 
Mahendra Kariya
Greenhorn
Posts: 26
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apple still not initialised.
 
Mahendra Kariya
Greenhorn
Posts: 26
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Local files cannot be accessed from an applet unless applet is digitally signed. What a silly mistake...!
 
Mahendra Kariya
Greenhorn
Posts: 26
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to AndrewThompson64 on Sun Forums. I changed the file path to URL and it worked fine. The code for that is below.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic