Issue1623

classification
Title: Using swing: JMenuBar instantiation has failed.
Type: crash Severity: urgent
Components: Jythonc compiler Versions: 2.5.1
Milestone:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: amak Nosy List: Carolinus, akong, amak, zyasoft
Priority: Keywords:

Created on 2010-06-27.09:26:17 by Carolinus, last changed 2010-07-19.22:55:28 by zyasoft.

Messages
msg5843 (view) Author: Thomas Lehmann (Carolinus) Date: 2010-06-27.09:26:16
Following code leads to the crash:
 - result can be seen after the code section

<code>
from javax.swing import JFrame
from javax.swing import JMenuBar

class Framework(JFrame):
    def __init__(self):
        JFrame.__init__(self)
        self.menuBar = JMenuBar()

        self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
        self.setLocation(50, 50)
        self.setSize(400, 400)
        self.setTitle("A title...")
        self.setJMenuBar(self.menuBar)
        self.setVisible(True)

if __name__ == "__main__":
    framework = Framework()
</code>

<result>
>C:\Jython2.5.1\jython.bat -u "dummy.py"
Traceback (most recent call last):
  File "dummy.py", line 17, in <module>
    framework = Framework()
  File "dummy.py", line 7, in __init__
    self.menuBar = JMenuBar()
TypeError: can't convert javax.swing.JMenuBar[,0,0,0x0,invalid,layout=javax.swing.plaf.basic.DefaultMenuLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.metal.MetalBorders$MenuBarBorder@158cc6,flags=392,maximumSize=,minimumSize=,preferredSize=,margin=,paintBorder=true] to java.awt.MenuBar
>Exit code: -1    Time: 2.925
</result>
msg5844 (view) Author: Anthony Kong (akong) Date: 2010-06-27.21:03:46
JFrame inherits from class java.awt.Frame a pair of setter and getter called setMenuBar and getMenuBar respectively. These methods return or take java.awt.Menubar. 

So, when you call

self.menuBar = JMenuBar()

jython resolved it to a call of setMenuBar and hence a conversion exception.

Rename menuBar to something else will avoid the exception
msg5850 (view) Author: Thomas Lehmann (Carolinus) Date: 2010-06-28.17:42:07
The same did not happen in Java so I have had no idea.
Thanks.
msg5870 (view) Author: Alan Kennedy (amak) Date: 2010-07-02.17:53:33
Is this issue resolved to the OP's satisfaction?

If so, I will close it.

Thanks to Anthony for the solution.
msg5905 (view) Author: Jim Baker (zyasoft) Date: 2010-07-19.22:55:28
Closed per discussion on #jython
History
Date User Action Args
2010-07-19 22:55:28zyasoftsetstatus: open -> closed
nosy: + zyasoft
messages: + msg5905
2010-07-02 17:53:33amaksetassignee: amak
messages: + msg5870
nosy: + amak
2010-06-28 17:42:08Carolinussetmessages: + msg5850
2010-06-27 21:03:47akongsetnosy: + akong
messages: + msg5844
2010-06-27 09:26:17Carolinuscreate