I see a number of things I don't like about that code, chief of which is that you are either calling
Thread.sleep(...) on the EDT, or calling Swing constructors and methods off of the EDT. Here's a resource to learn more about that:
Lesson: Concurrency in Swing.
Then, I don't really understand why you are using a
text component to display an image. What's wrong with a JLabel and icon?
Third, you are apparently constructing an
ImageIcon only to obtain the image's height. If you
must load the image twice, you could save a little overhead -- and the likelihood of the image being not completely loaded when you query the height, possibly one cause of the resizing you observed -- by reading it to a
BufferedImage with
ImageIO.
Fourth, you are needlessly discarding away any information contained in any
Exception by throwing a new
IllegalArgumentException from the catch block. If your design requires this (it shouldn't), at the very least
you should print or log the stack trace of the original
Exception.