tags:

views:

62

answers:

1

Today, I've been dabbling in using jython to create a GUI using swing. I'm no expert programmer, so I decided to have a go at using the Netbeans IDE to design the interface and then adapt the output for use in jython as I have more experience in python than Java. After working through the code I managed to rid all the syntax errors but am still left with an error that reads:

Traceback (most recent call last):
   File "<path of file>", line 362, in     <module>
run = InitGUI()
   File "<path of file>", line 358, in __init__
frame.show()
    at javax.swing.GroupLayout.checkParent(Unknown Source)

    at javax.swing.GroupLayout.invalidateLayout(Unknown Source)

    at java.awt.Container.invalidate(Unknown Source)

    at java.awt.Component.addNotify(Unknown Source)

    at java.awt.Container.addNotify(Unknown Source)

    at javax.swing.JComponent.addNotify(Unknown Source)

    at java.awt.Container.addNotify(Unknown Source)

    at javax.swing.JComponent.addNotify(Unknown Source)

    at java.awt.Container.addNotify(Unknown Source)

    at javax.swing.JComponent.addNotify(Unknown Source)

    at javax.swing.JRootPane.addNotify(Unknown Source)

    at java.awt.Container.addNotify(Unknown Source)

    at java.awt.Window.addNotify(Unknown Source)

    at java.awt.Frame.addNotify(Unknown Source)

    at java.awt.Window.show(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)


java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: GroupLayout can only be used with one Container at a time

Now, I have no idea what has caused this, or how/where to look to go about solving it.

Full source code is here.

I would really appreciate it if anyone could take a look,

Thanks

+3  A: 

You're setting the Layout on the JFrame which I have never seen before.. (normally one sets the layout of the child components of the JFrame).

Can you try:

layout = GroupLayout(frame.getContentPane())
frame.getContentPane().setLayout(layout)

See also this discussion.

Andre Holzner
Fantastic! worked like a charm. Thanks so much :)
matt_t
+1. Interesting, a case where the forwarding all calls to the contentPane by a JFrame turns ugly. The checkParent method of GroupLayout only checks for reference equality which fails with contentPane != JFrame since it has no special handling for JFrame.
josefx