在NetBeans GUI Designer中重用JPanel [英] Reusing a JPanel in NetBeans GUI Designer
问题描述
这是在NetBeans 6.5,Java 6中。
This is in NetBeans 6.5, Java 6.
我在NetBeans GUI Designer中有以下层次结构:
I have the following hierarchy in the NetBeans GUI Designer:
JFrame
JTabbedPane
JPanel X
<...>
JPanel
JButton
JPanel Y
<...>
JButton
问题:
JPanel Y与JPanel X相同,所以我想在两个地方重复使用JPanel X,但是如何在GUI Builder中执行此操作?
Question:
JPanel Y is identical to JPanel X, so I'd like to simply reuse JPanel X in both places, but how do I do this inside the GUI Builder?
我尝试复制粘贴JPanel X,但它创建了一个完整的深度副本(JPanel X1等),复制了JPanel X中的所有内容。
I tried copy-pasting JPanel X, but it creates a full "deep" copy (JPanel X1, etc), duplicating everything in JPanel X.
一些谷歌搜索表明可以将它添加到Palette中,但我还没有找到一种方法将简单的JPanel添加到调色板(而不是完整的JFrame)。
Some googling indicated it might be possible to add it to the Palette, but I haven't found a way to add a simple JPanel to the palette (as opposed to a complete JFrame).
推荐答案
创建一个单独的JPanel类。根据需要自定义JPanel。然后,您可以将JPanel类拖放到表单设计器上。这正是我所做的。
Create a separate JPanel class. Customize JPanel as needed. You can then drag-and-drop the JPanel class onto the Form Designer. This is exactly what I do.
或者,您可以单击使用Bean,然后键入类的名称。
Alternatively, you can click on Use Bean and then type in the name of the class.
或者,您可以从托盘中执行添加,它将扫描您的JAR以查找任何bean。它也应该选择你的自定义JPanel。
Alternatively, you can do an Add from the pallete and it will scan your JAR for any "beans". It should pick up your custom JPanel as well.
这篇关于在NetBeans GUI Designer中重用JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!