With slight modifications, it worked for me (Jython 2.1,Win2k, JDK1.4).
Here's my version:
from javax.swing import *
class MyCellRenderer(JLabel, ListCellRenderer):
def __init__(self):
self.myIcon = ImageIcon("someicon.gif")
def getListCellRendererComponent(self ,list, value, isIndex, selected,
cellHasFocus):
s = `value`
# This works better, it doesn't put quotes in s
# s = java.lang.String.valueOf(value)
# Gratuitous converson to jython bean-property syntax:
self.text = s
self.icon = self.myIcon
self.opaque = 1
return self
myList = JList(["this","is","a","test"])
myList.setCellRenderer(MyCellRenderer())
f = JFrame()
f.contentPane.add(JScrollPane(myList))
f.pack()
f.show()
David Robertson wrote:
> Does anyone have any tips on how I can get the following to work.
>
> from javax.swing import *
>
> class MyCellRenderer(JLabel, ListCellRenderer):
> def OnInit(self):
> self.myIcon = ImageIcon("someicon.bmp")
> def getListCellRendererComponent(self ,list, value, isIndex, selected,
> cellHasFocus):
> s = value.toString()
> setText(s)
> setIcon(self.myIcon)
> setOpaque(true)
> return self
>
> myList = JList(["this","is","a","test"])
> myList.setCellRenderer(MyCellRenderer())
>
> The constructor for MyCellRenderer is called, but
> getListCellRendererComponent is never called. I have tried many different
> combos, and read all jython docs I could find.
>
> I am in the process of writing a FTP browser plugin for Jext because the one
> offered on thier site does not work, I have everything coded except the
> above (which is just a very brief version). I was trying to write it in
> Jython first as a test bed.
>
> Thanks, Dave
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by: OSDN - Tired of that same old
> cell phone? Get a new here for FREE!
> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
> _______________________________________________
> Jython-users mailing list
> Jython-users@...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
|