Swing:如何才能让 JInternalFrame 与容器内的其他组件受到同等对待?

发布于 2024-07-25 02:39:54 字数 1057 浏览 9 评论 0原文

背景信息:

我正在实现一个可视化图表编辑器,它由

  • 不同的复杂元素(可调整大小,带标题栏,子元素)和
  • 不同的简单元素(不可调整大小,无标题栏) 组成,没有子元素)。

所有元素都是可拖动的。

我正在使用 JInternalFrame (用于复杂元素)以及 JPanel (对于简单元素)表示示意图的元素。 有一个容器(JDesktopPane 或 JLayeredPane),其中包含 所有这些元素。

我对这个概念有几个问题:

情况 1 - 容器是 JDesktopPane:

  • JInternalFrames 始终位于其他元素之上。
  • 单击其他元素不会“停用”先前处于活动状态的 JInternalFrame

情况 2 - 容器是 JLayeredPane:

  • 单击 JInternalFrame 内的某些元素后,它会保持不变 永远“激活”。

情况 3 - JInternalFrame 用于所有内容,但没有简单元素的装饰:

  • 我的自定义边框(当我手动删除时需要它 JInternalFrame 的标题栏) 每次都会被当前的 LAF 边框替换,之后 激活/停用 JInternalFrame。

无论如何,我不明白激活 JInternalFrames 背后的整个概念。 如果我可以使 JInternalFrame 根本不可激活,我可以 选择情况 2 任何人都会很高兴。

请告诉我,对于给定的问题,什么是简单直接的解决方案。

注意:组件的选择和JInternalFrame的激活 似乎是不同的东西。

Background information:

I am implementing a visual diagram editor, which consists of

  • different complex elements (re-sizable, with title bar, sub-elements) and
  • different simple elements (not re-sizable, no title bar, no sub-elements).

All elements are draggable.

I am using JInternalFrame (for complex elements) along with JPanel
(for simple elements) to represent elements of a schematic diagram. There is a container (either a JDesktopPane or a JLayeredPane), which contain
all these elements.

I have several problems with this concept:

Case 1 - The container is a JDesktopPane:

  • JInternalFrames are always above other elements.
  • Clicking other elements don't "deactivate" previously active JInternalFrame

Case 2 - The container is a JLayeredPane:

  • After clicking some elements inside a JInternalFrame, it stays
    "activated" forever.

Case 3 - JInternalFrame used for everything, but without decoration for simple elements:

  • My custom border (which is needed when I manually remove
    JInternalFrame's title bar)
    is every time replaced by current LAF border, after
    activating/deactivating the JInternalFrame.

I don't get the whole concepts behind activating JInternalFrames anyway.
If I could make a JInternalFrame not activable at all, I could
choose Case 2 any would be happy.

Please advice me, what would be an simple and straightforward solution to given problems.

NOTE: Selection of components and activation of JInternalFrame
seem to be different things.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安静被遗忘 2024-08-01 02:39:54

我可能会误解你的问题。 您是否尝试过查看 JIF 的 setSelected() 方法? 似乎支持方法覆盖和可否决激活事件。

编辑:也许我们有一些术语误解,正如javadoc所述:

/**
 * Selects or deselects the internal frame
 * if it's showing.
 * A <code>JInternalFrame</code> normally draws its title bar
 * differently if it is
 * the selected frame, which indicates to the user that this
 * internal frame has the focus.
 * When this method changes the state of the internal frame
 * from deselected to selected, it fires an
 * <code>InternalFrameEvent.INTERNAL_FRAME_ACTIVATED</code> event.
 * If the change is from selected to deselected,
 * an <code>InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED</code> event
 * is fired.
 *
 * @param selected  a boolean, where <code>true</code> means this internal frame
 *                  should become selected (currently active)
 *                  and <code>false</code> means it should become deselected
 * @exception PropertyVetoException when the attempt to set the
 *            property is vetoed by the <code>JInternalFrame</code>
 *
 * @see #isShowing
 * @see InternalFrameEvent#INTERNAL_FRAME_ACTIVATED
 * @see InternalFrameEvent#INTERNAL_FRAME_DEACTIVATED
 *
 * @beaninfo
 *     constrained: true
 *           bound: true
 *     description: Indicates whether this internal frame is currently
 *                  the active frame.
 */

编辑2:现在我重新阅读你的第二个案例。 我想说每个 JIF 都有自己独立的焦点/选择环境。 您可以创建一个方法来遍历所有 JIF 并取消选择其中的任何内容,除非它是您想要选择的组件。

I might misunderstand your problem. Have you tried to look at the setSelected() method of JIF? It seems there are support for method override and vetoable activation events.

Edit: Maybe we have some terminological misunderstanding as the javadoc states:

/**
 * Selects or deselects the internal frame
 * if it's showing.
 * A <code>JInternalFrame</code> normally draws its title bar
 * differently if it is
 * the selected frame, which indicates to the user that this
 * internal frame has the focus.
 * When this method changes the state of the internal frame
 * from deselected to selected, it fires an
 * <code>InternalFrameEvent.INTERNAL_FRAME_ACTIVATED</code> event.
 * If the change is from selected to deselected,
 * an <code>InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED</code> event
 * is fired.
 *
 * @param selected  a boolean, where <code>true</code> means this internal frame
 *                  should become selected (currently active)
 *                  and <code>false</code> means it should become deselected
 * @exception PropertyVetoException when the attempt to set the
 *            property is vetoed by the <code>JInternalFrame</code>
 *
 * @see #isShowing
 * @see InternalFrameEvent#INTERNAL_FRAME_ACTIVATED
 * @see InternalFrameEvent#INTERNAL_FRAME_DEACTIVATED
 *
 * @beaninfo
 *     constrained: true
 *           bound: true
 *     description: Indicates whether this internal frame is currently
 *                  the active frame.
 */

Edit 2: Now I re-read your 2nd case. I would say each JIF has its own separated focus/selection environment. You could create a method which traverses all your JIFs and deselects anything in it unless its the component you wanted to be selected.

空心空情空意 2024-08-01 02:39:54

在初始化 JInternalFrame= 时尝试一下,

 new JInternalFrame(<your args>) {
          protected void fireInternalFrameEvent(int id){  
               if (id != InternalFrameEvent.INTERNAL_FRAME_ACTIVATED) {
                   super.fireInternalFrameEvent(id);
               }
          }
 };

请注意查看 JInternalFrame.setSelected(boolean) 中的代码,setSelected 和 'actvation' 在进程中绑定在一起,因为 setSelected 不仅会触发属性更改用于选择,还调用 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED)

give this a try when you initialize your JInternalFrame=

 new JInternalFrame(<your args>) {
          protected void fireInternalFrameEvent(int id){  
               if (id != InternalFrameEvent.INTERNAL_FRAME_ACTIVATED) {
                   super.fireInternalFrameEvent(id);
               }
          }
 };

note that looking at the code in JInternalFrame.setSelected(boolean), setSelected and 'actvation' are tied together in process, in that setSelected fires not only property changes for Selection, but also calls fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED) as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文