在 NetBeans GUI 设计器中重用 JPanel [英] Reusing a JPanel in NetBeans GUI Designer

查看:17
本文介绍了在 NetBeans GUI 设计器中重用 JPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在 NetBeans 6.5、Java 6 中.

This is in NetBeans 6.5, Java 6.

我在 NetBeans GUI 设计器中有以下层次结构:

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.

一些谷歌搜索表明可能可以将其添加到调色板中,但我还没有找到将简单的 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 设计器中重用 JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆