Netbeans:在常规 Java 类文件上使用 GUI Builder

发布于 2024-08-09 20:04:10 字数 166 浏览 10 评论 0原文

我正在使用 Netbeans。当我创建 Java 类时,有时我想将其更改为 GUI 组件,以便我可以使用 GUI 构建器对其进行可视化编辑。

将常规 Java 类转换为 GUI 组件以便 Netbeans 能够识别它并允许我使用 GUI Builder 的必要步骤是什么? (即在源代码和设计之间切换)

I'm using Netbeans. When I create a Java class, I sometimes want to change it to be a GUI component so that I can visually edit it using the GUI Builder.

What is the necessary step to transform a regular Java class to a GUI component so that Netbeans would recognize it and allow me to use GUI Builder ? (i.e. switch between Source and Design)

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

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

发布评论

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

评论(3

策马西风 2024-08-16 20:04:10

NetBeans 的 Gui 构建器 Matisse 处理位于源文件附近的 .form xml 文件。 Matisse 创建并维护 .form 文件,代码生成器在 java 源中创建/更新方法以反映对表单的更改。

不幸的是,NetBeans 不支持自由格式的 GUI 构建。

我见过的最接近的是 FormGenerator。它是一个贡献的 NetBeans 模块,它将右键单击操作添加到 .java 文件,该操作将尝试从 .java 源生成 .form 文件。虽然非常有限,但总比没有好。如果您遵循马蒂斯所采用的编码风格,那么它的效果最好。

http://netbeans.org/projects/contrib/downloads/download/Readme。文本
http://netbeans.org/projects/contrib/downloads/download/FormGeneratorModule。邮编

NetBeans' Gui builder, Matisse, works off a .form xml file located adjacent to the source file. Matisse creates and maintains the .form file and the code generator creates/updates methods in the java source to reflect changes to the form.

Unfortunately, there is no support in NetBeans for free-form GUI construction.

The closest I've seen is FormGenerator. It's a contributed NetBeans module that adds a right click action to .java files that will attempt to generate a .form file from the .java source. It's very limited, but it's better than nothing. It works best if you've followed the coding style employed by Matisse.

http://netbeans.org/projects/contrib/downloads/download/Readme.txt
http://netbeans.org/projects/contrib/downloads/download/FormGeneratorModule.zip

灯下孤影 2024-08-16 20:04:10

要将类添加到 Palette,所需要做的就是让您的类符合 Java Bean 模型。也就是说,您的类必须:

  • 可序列化
  • 有一个公共的、无参数的构造函数。

所有具有正确命名的 getter 和 setter 方法的字段,即:

int count
int getCount()
void setCount(int c)

默认情况下应被识别为属性。

为了更好地控制哪些属性应该和不应该暴露给 GUI 构建器,您可以将您的类与 BeanInfo 接口。有关更多详细信息,请参阅此 Sun 教程

不过,NetBeans 有多种工具可以帮助您设计自定义 Bean。您可以使用“JavaBeans Objects”文件夹下的新文件对话框中提供的内置模板来创建新 bean。
教程将指导您创建图像Bean。

您可以做的是从头开始创建一个类,按照您的意愿设计它,然后查看生成的代码以了解如何修改现有的类。

To add a class to the Palette, all that's needed is for your class to conform to the Java Beans model. That is, your class must:

  • be serializable
  • have a public, no-argument constructor.

All fields that have getter and setter methods that are named properly, i.e.:

int count
int getCount()
void setCount(int c)

should by default be recognized as a property.

For a finer control of what properties should and should not be exposed to the GUI Builder, you can associate your class with an implementation of the BeanInfo interface. See this Sun tutorial for more details.

However, NetBeans has several tools to help you in designing a custom bean. You can create new beans using the built-in templates available in the new file dialog, under the "JavaBeans Objects" folder.
This tutorial will guide you through creating an Image Bean.

What you could do is create one from scratch, design it as you wish, and then look at the generated code to understand how you can modify your existing class.

许久 2024-08-16 20:04:10

尝试使用属性(Java bean!)作为应从 UI 设计器更改的属性,并查看此处了解更多信息。

Try to use properties (Java bean!) for properties which should be changed from the ui designer and look here for more info.

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