简体   繁体   English

在NetBeans GUI Designer中重用JPanel

[英]Reusing a JPanel in NetBeans GUI Designer

This is in NetBeans 6.5, Java 6. 这是在NetBeans 6.5,Java 6中。

I have the following hierarchy in the NetBeans GUI Designer: 我在NetBeans GUI Designer中具有以下层次结构:

JFrame
  JTabbedPane
    JPanel X
      <...>
    JPanel
      JButton
      JPanel Y
        <...>
      JButton

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 Y与JPanel X完全相同,所以我想在两个地方重复使用JPanel X,但是我如何在GUI Builder中执行此操作?

Attempts: 尝试:

I tried copy-pasting JPanel X, but it creates a full "deep" copy (JPanel X1, etc), duplicating everything in JPanel X. 我尝试复制粘贴JPanel X,但它创建了一个完整的“深度”副本(JPanel X1等),复制了JPanel X中的所有内容。

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). 一些谷歌搜索表明它可能会添加到Palette,但我还没有找到一种方法将简单的JPanel添加到调色板(而不是完整的JFrame)。

Create a separate JPanel class. 创建一个单独的JPanel类。 Customize JPanel as needed. 根据需要自定义JPanel。 You can then drag-and-drop the JPanel class onto the Form Designer. 然后,您可以将JPanel类拖放到表单设计器上。 This is exactly what I do. 这正是我的工作。

Alternatively, you can click on Use Bean and then type in the name of the class. 或者,您可以单击“使用Bean”,然后键入类的名称。

Alternatively, you can do an Add from the pallete and it will scan your JAR for any "beans". 或者,您可以从托盘执行添加,它将扫描您的JAR以查找任何“bean”。 It should pick up your custom JPanel as well. 它也应该选择你的自定义JPanel。

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

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