简体   繁体   English

在Netbeans面板中分解Java Swing类

[英]Breaking up Java Swing classes in Netbeans palette

I would like to know the best method of breaking up large Java Swing classes. 我想知道分解大型Java Swing类的最佳方法。 Some of mine are quite large and I would like to begin the process of properly modularizing my code. 我的一些东西很大,我想开始适当地模块化我的代码的过程。 I saw that I could add my classes to Netbeans' palette but the problem is they are not showing me a graphical representation of what it will look like when I "drop" them into the GUI designer. 我看到可以将类添加到Netbeans的调色板中,但是问题是它们没有向我显示将它们“拖放”到GUI设计器中时的外观。 Some third party jar files support getting added to the palette and they provide a graphical preview of what they'll look like once run. 一些第三方jar文件支持添加到面板中,并且它们提供了图形预览,显示了它们一旦运行后的外观。

My question is, I don't know the proper terminology for what this "preview" is called so I'm finding it very difficult to search for. 我的问题是,我不知道该“预览”的正确术语,因此我发现搜索非常困难。 I would like some documentation or a tutorial on how to make my current classes able to be added to the palette and see what it is they will look like in the GUI designer. 我想要一些文档或教程,以了解如何使当前的类能够添加到选板并查看它们在GUI设计器中的外观。

Thank you! 谢谢!

To get an icon, you need to provide a BeanInfo for you class. 要获取图标,您需要为您的类提供BeanInfo

The easiest way to do this is right click on the class in the Project window and select BeanInfo editor... . 最简单的方法是在“项目”窗口中右键单击该类,然后选择BeanInfo editor...

You'll want to switch to the designer view to configure which properties are expert/hidden/preferred. 您将要切换到设计器视图,以配置哪些属性是专家/隐藏/首选。

  • Preferred properties appear in the top most fold (Properties) of the Property window. 首选属性出现在“属性”窗口的最上面的折页(“属性”)中。
  • Expert properties appear in the second fold (Other Properties). 专家属性出现在第二折中(其他属性)。
  • Hidden do not appear at all. 隐藏根本不会出现。

You can also specify whether properties are bound, constrained, etc. To set icons, choose the topmost node of the tree (BeanInfo) and you'll see properties for the icons. 您还可以指定属性是否绑定,受约束等。要设置图标,请选择树的最顶层节点(BeanInfo),然后将看到图标的属性。

To make NetBeans treat your component as a container (or not a container): 要使NetBeans将组件视为容器(或不是容器),请执行以下操作:

  • Switch to Source view 切换到源视图
  • Find the line reading 查找线读数
    // Here you can add code for customizing the BeanDescriptor.
  • Add this line: 添加此行:
    beanDescriptor.setValue("isContainer", Boolean.TRUE); // Or FALSE if it's not a container

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM