今天,我一直在尝试使用jython来使用swing创建GUI。我不是专家程序员,所以我决定使用Netbeans IDE设计界面,然后调整输出以便在jython中使用,因为我在python中比Java更有经验。在完成代码之后,我设法摆脱了所有的语法错误,但仍然留下了一个错误:
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
现在,我不知道造成这种情况的原因,以及如何/在哪里寻求解决它。
完整源代码为here.
如果有人能看一眼我真的很感激,
由于
答案 0 :(得分:4)
您正在JFrame
上设置我以前从未见过的布局..(通常会设置JFrame
的子组件的布局。
你可以尝试:
layout = GroupLayout(frame.getContentPane())
frame.getContentPane().setLayout(layout)