Issue1749824

classification
Title: Cannot assign to actionPerformed
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, dennisn
Priority: normal Keywords:

Created on 2007-07-08.05:50:30 by dennisn, last changed 2007-07-08.21:20:58 by cgroves.

Messages
msg1708 (view) Author: Dennis Newbold (dennisn) Date: 2007-07-08.05:50:30
Interactive mode Screenshot shown below:
C:\>jython
Jython 2.2rc1 on java1.6.0_01
Type "copyright", "credits" or "license" for more information.
>>> import javax.swing
>>> def note_check(e):
...     pass
...
>>> xbox = javax.swing.JCheckBox("Chocolate Cake",itemStateChanged=note_check)
>>>
>>> def select_jc_item(e):
...     pass
...
>>> jc = javax.swing.JComboBox(["Harry", "Sally", "Turtle"], actionPerformed=sel
ect_jc_item)
Traceback (innermost last):
  File "<console>", line 1, in ?
TypeError: can't assign to this attribute in java instance: actionPerformed
>>>

It appears that I can assign a function to the itemStateChanged attribute of a JCheckBox, but I
cannot assign a function to the actionPerformed
attribute of a JComboBox.  I have no idea why, but it is
rather frustrating.  I think of it as a bug.  Perhaps
you view it as a "feature".  Any help / suggestions
will be appreciated as currently I am stuck.

dennisne@gmail.com
dln@andrew.cmu.edu
msg1709 (view) Author: Charlie Groves (cgroves) Date: 2007-07-08.21:20:58
JComboBox has a method actionPerformed since it implements ActionListener.  A method is higher in the visibility ordering than a bean event property, so it's taking precedence and coming back for actionPerformed as explained on http://jython.org/Project/userguide.html#methods-properties-and-event-properties.  Jython is complaining that it can't assign your method on top of the existing JComboBox actionPerformed method.  

You can get around this by using the more cumbersome addActionListener method.  Create a Python class that implements ActionListener, put your select_jc_item method in it as "actionPerformed" and call jc.addActionListener with an instance of your ActionListener subclass.

In the future, send stuff where you're not sure if it's a bug or not to jython-users. Many more people monitor it so you have a better chance at a timely response, and answers there turn up more readily in search results than the bug database.
History
Date User Action Args
2007-07-08 05:50:30dennisncreate