将 Java GUI Builder .form 文件转换为源代码?

发布于 2024-07-18 00:49:29 字数 152 浏览 3 评论 0原文

我创建了一个相当大的 Java GUI 应用程序,其中包含许多表单窗口,其中的设置被锁定在 .form 文件中。 我想知道是否有任何方法可以将这些 .form 文件转换或重构为我可以修改的真正的 Java 源代码?

GUI 是使用 Netbeans 6.5 创建的。

I have created a fairly substantial Java GUI application with many form windows where the settings are locked up in .form files. I am wondering is there any way to convert or refactor these .form files into real Java source code that I can modify?

The GUI was created using Netbeans 6.5.

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

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

发布评论

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

评论(3

岛歌少女 2024-07-25 00:49:29

我的理解是,“.form”文件仅由 Netbeans GUI 构建器用来跟踪 GUI 组件的位置。 当您在设计视图中添加组件时,Netbeans 会自动更新实际的源 (.java) 文件。 实际上,您可以直接修改这些 .java 文件,例如更改按钮上的标签,但如果您在 Netbeans 中执行此操作,它将使用 .form 文件自动重新生成源文件,从而破坏您的手动更改。

根据我的经验,一旦您决定手动修改 .java 文件,.form 文件就会不同步,您将无法再正确使用 Netbeans GUI 构建器。

My understanding is that the ".form" files are only used by the Netbeans GUI builder to keep track of where the GUI components are. When you add components in the design view, Netbeans automatically updates the actual source (.java) files. You can actually modify these .java files directly to, say, change the label on a button, but if you do it within Netbeans, it will use the .form files to automatically regenerate the source files, destroying your manual changes.

In my experience, once you make the decision to modify the .java files manually, the .form files become out of sync and you will no longer be able to use the Netbeans GUI builder properly.

烧了回忆取暖 2024-07-25 00:49:29

kazanaki 是对的,生成的 java 文件可以修改,但生成的 .java 文件非常混乱、庞大且难以解释。 此外,您无法更改某些内容(如生成的 .java 文件中的注释中所述)而不会使 matisse 无用,因为它期望文件以某种方式包含内容。 话虽如此,如果您小心不要踩到马蒂斯的脚趾,您就可以继续编写代码,并且它不会影响您的代码,这很好。

奥特洛也是对的,如果你改变了马蒂斯视野中已有的任何东西,它就会被覆盖。 您在 matisse 外部进行的任何更改都必须位于 matisse 用于生成代码的 xml 所覆盖的任何元素之外。

我以前尝试过这种事情,但效果有限,最终只是重写了界面以避免这些令人抓狂的头痛。

kazanaki is right, the java files that are generated can be modified but the resulting .java files are notoriously messy, large and hard to interpret. Also, you cannot change some things (as noted in the comments in the generated .java file) without rendering matisse useless because it expects the file to have things in a certain way. That being said, if you are careful not to step on Matisse's toes you can code away and it will not touch your code which is nice.

Outlaw is right too, if you change anything that is already in Matisse's perview it will be overwritten. Any changes that you make outside of matisse must be outside of any element that is covered by the xml that matisse uses to generate the code.

I have tried this kind of thing before with limited success and eventually just rewrote the interface to avoid these maddening headaches.

琉璃繁缕 2024-07-25 00:49:29

我可以编辑源代码,我发现了解决方案。 问题是我在 GUI 构建器中使用了“AbsoluteLayout”。 Netbeans 正在创建一些位于 .form 文件内的隐藏的 AbsoluteLayout 类。 如果我删除了 .form 文件,该项目将不再构建。 解决方案是将表单更改为“FreeForm”布局,然后我可以删除 .form 文件并删除 GUI 构建器注释。

谢谢你们的帮助,我给你们都+1。

I can edit the source, I discovered the solution. THe problem was that I was using the "AbsoluteLayout" in the GUI builder. Netbeans was creating some hidden AbsoluteLayout class that was inside the .form files. IF I deleted the .form files the project would no longer build. The solution was to change the form to be of "FreeForm" layout and then I could delete the .form files and remove the GUI builder comments.

Thank you for the help guys, I give you both +1.

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