在 Jython 中创建基于 Swing 的 GUI

发布于 2024-09-19 02:02:01 字数 1749 浏览 2 评论 0原文

今天,我一直在尝试使用 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

现在,我不知道是什么导致了这个问题,也不知道如何/在哪里解决它。

完整的源代码位于此处。

如果有人可以看一下,我将非常感激,

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸 2024-09-26 02:02:01

您正在 JFrame 上设置我以前从未见过的布局..(通常设置 JFrame 的子组件的布局)。

您可以尝试一下:

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

另请参阅此讨论

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文