Question

Still pretty green on clojure, java, layouts etc. On a miglayout I have this line to insert an icon on Jlabel:

(JLabel. "" "C:\\MyPriject\Pictures\\TCM00.jpg")

I am getting the following error:

#<CompilerException java.lang.IllegalArgumentException: No matching ctor found for class javax.swing.JLabel (NO_SOURCE_FILE:901)>

Any help will be highly appreciated.

Was it helpful?

Solution

JLabel has no constructor that takes two String arguments.

If you want just an icon (and no text), there is a constructor that takes one Icon. The class ImageIcon (which implements Icon) has a constructor that takes a filename String. So this should work:

(JLabel. (ImageIcon. "C:\\MyPriject\Pictures\\TCM00.jpg"))

See the javadoc:
http://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/JLabel.html
http://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/ImageIcon.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top