How to include custom panel with NetBeans GUI Builder?

你离开我真会死。 提交于 2019-11-26 12:46:48

问题


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.


回答1:


Simply drag the class from the projects tree on to the form in the GUI designer.

Just like it says in stackoverflow question 691890.




回答2:


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.
See How can I use a custom subclass of a Swing component? in the NetBeans Wiki.




回答3:


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.



来源:https://stackoverflow.com/questions/816286/how-to-include-custom-panel-with-netbeans-gui-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!