I’d like to create a small Java applet that displays a message and a graphic, but done using Jython. Using the code below I get the error message “TypeError: setIcon(): 1st arg can’t be coerced to javax.swing.Icon”
Can anyone offer advise as to
- How I can get this chunk of code working?
- Where I might find Jython examples that build GUI windows using Java.swing objects?
Many thanks indeed!
-thescoop.
#############################
from javax.swing import JFrame;
from javax.swing import *;
from java.awt import *;
jf = JFrame();
jf.setSize(500,500);
jf.setLocation(100, 50);
jf.setTitle('This is the title');
jf.setLayout(FlowLayout());
l = JLabel();
l.setIcon('lena.png');
jf.add(l);
jf.pack();
jf.setVisible(True);
#
The problem is in
l.setIcon('lena.png');thesetIcon()method expects an Icon and not a string. The correct way is to create anImageIconand then use it. For example:The
croco.pngis a test image on my system.