如何使用 NetBeans GUI Builder 包含自定义面板?
我编写了一个扩展 JPanel 的类。 是否可以在 NetBeans GUI Builder 中使用它并让它在所有自动代码生成过程中幸存下来?
我已经使用 GUI 构建器中的自定义代码选项将对象实例化为新类,但似乎无法从 JPanel 更改声明,因此只有我重写的方法才会被调用,我无法调用 new JPanel 中不存在的内容。
I have written a class that extends JPanel. Is it possible to use this in the NetBeans GUI Builder and have it survive all of the automatic code generation?
I have used the customised code option in the GUI builder to instantiate the object as the new class, but it seems like the declaration can't be changed from JPanel, so only methods that I have overridden get called, I can't call new ones that are not present in JPanel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需将类从项目树拖到 GUI 设计器中的窗体即可。
就像stackoverflow问题691890中所说的那样。
Simply drag the class from the projects tree on to the form in the GUI designer.
Just like it says in stackoverflow question 691890.
您可以使用调色板管理器将组件添加到调色板,然后可以像使用任何其他类一样在 GUI 构建器中使用它。
NetBeans Wiki 曾一度对此进行了介绍,但现已不复存在。 现在我能找到的唯一官方文档是 Apache NetBeans 知识库:
You can use the Palette Manager to add your component to the palette, then you can use it in the GUI builder as you would any other class.
At one point this was covered on the NetBeans Wiki, which is now defunct. Now the only official documentation I can find on it is in the new Apache NetBeans knowledge base:
只需为您的类提供一个公共的无参数构造函数即可。 然后,您可以通过右键单击类并选择“添加到调色板”来将类添加到调色板。
Just provide a public no-arg constructor for your class. You can then add the class to the Palette by right clicking on it and selecting Add to Palette.