fejd
fejd

Reputation: 2565

Jython mouse listener on JLabel results in TypeError

I'm making an application in Jython where I try to capture mouse events on a JLabel. I have a JFrame that contains a JLabel, but when I try to add a mouse listener to it I get:

TypeError: write only attribute

The main window:

class Commander(JFrame):
    ...
    self.image = ImageIcon()
    self.label = JLabel(self.image)
    self.mouseListener = ScreenMouseListener()
    self.label.addMouseListener(self.mouseListener) <- This line causes the TypeError
    ...

The mouse listener extends MouseAdapter:

class ScreenMouseListener(MouseAdapter):
    def mousePressed(self, event):
        print "Mouse pressed"

Searching for the error leads me to PyBeanEvent, but I don't understand why it happens. Which attribute is write-only?

Edit: After removing the line that caused the error, I noticed that the mousePressed function gets called! Is "mouseListener" perhaps a property of JFrame?

Upvotes: 2

Views: 833

Answers (1)

fejd
fejd

Reputation: 2565

I believe JFrame.mouseListener is a write-only property, i.e. there is no get function implemented, so when it was passed to self.label.addMouseListener, it could not be read. Solved it by doing the following instead:

self.label.addMouseListener(ScreenMouseListener())

Upvotes: 0

Related Questions