This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

Santiago Escobar Robledo

Greenhorn
+ Follow
since Apr 17, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Santiago Escobar Robledo

It's so late to answer, but to someone this could be useful ...

Daniel Searson wrote:The exception you are getting is because you are in a Java applet and Java applets aren't allowed to access other files. The method getImage() in the Applet/JApplet class is a way around this (I'm not entirely sure how it works, but it does). Creating an ImageIcon using "new ImageIcon()" is not possible because it relies on normal I/O. So you get an access permission exception.



That's true.

So, with ImageIcon you could do two things to avoid the AccessControlException because java.io.FilePermission:

1. To grant explicit permission to access local system resources ... resources that you will use in the applet.


You could see the next link about "Security and Permissions": http://java.sun.com/developer/onlineTraining/Programming/JDCBook/appA.html


2. To use ClassLoader

For example:


Everything is in the same path:

src/
- ImageIcon.java
- image.jpg
- index.html -> To run the applet

You could see the next link: http://www.leepoint.net/notes-java/GUI-lowlevel/graphics/45imageicon.html


By the way, ImageIcon doesn't allow to resize the image. You could see this post: https://coderanch.com/t/331731/GUI/java/Resize-ImageIcon. It works perfect.

12 years ago