Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Swing:如何使JInternalFrame与容器中的其他组件同等对待?_Java_User Interface_Swing_Jinternalframe_Jdesktoppane - Fatal编程技术网

Java Swing:如何使JInternalFrame与容器中的其他组件同等对待?

Java Swing:如何使JInternalFrame与容器中的其他组件同等对待?,java,user-interface,swing,jinternalframe,jdesktoppane,Java,User Interface,Swing,Jinternalframe,Jdesktoppane,背景资料: 我正在实现一个可视化的图表编辑器,它包括 不同的复杂元素可重新调整大小,包括标题栏、子元素和 不同的简单元素不可重新调整大小,没有标题栏,没有子元素。 所有元素都可以拖动 我将JInternalFrame与JPanel一起用于复杂元素 用于表示原理图元素的简单元素。有一个容器JDesktopPane或JLayeredPane,其中包含 所有这些因素 我对这个概念有几个问题: 案例1-容器是一个JDesktopPane: JInternalFrames总是高于其他元素。 单击其他元素不

背景资料:

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

不同的复杂元素可重新调整大小,包括标题栏、子元素和 不同的简单元素不可重新调整大小,没有标题栏,没有子元素。 所有元素都可以拖动

我将JInternalFrame与JPanel一起用于复杂元素 用于表示原理图元素的简单元素。有一个容器JDesktopPane或JLayeredPane,其中包含 所有这些因素

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

案例1-容器是一个JDesktopPane:

JInternalFrames总是高于其他元素。 单击其他元素不会停用以前激活的JInternalFrame 案例2-容器是一个JLayeredPane:

单击JInternalFrame中的某些元素后,它将保持不变 永远激活。 案例3-JInternalFrame适用于所有用途,但不适用于简单元素的装饰:

手动删除时需要的自定义边框 JInternalFrame的标题栏每次在 激活/停用JInternalFrame。 我不明白激活JInternalFrames背后的全部概念。 如果我能使JInternalFrame完全不可激活,我可以 选择案例2,任何人都会很高兴

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

注:组件的选择和JInternalFrame的激活
看起来不一样。

我可能误解了你的问题。你有没有试过看看JIF的方法?似乎支持方法重写和可否决的激活事件

编辑:也许我们有一些术语上的误解,正如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并取消选择其中的任何内容,除非它是您想要选择的组件。

在初始化JInternalFrame时尝试一下=

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

请注意,查看JInternalFrame.setSelectedboolean中的代码,setSelected和“actvation”在这个过程中是绑定在一起的,因为setSelected不仅触发用于选择的属性更改,还调用fireInternalFrameEventInternalFrameEvent.INTERNAL_FRAME_

是的,但是没有用。选择与JInternalFrame的激活无关。你看,即使在Javadoc中,它也令人困惑。他们谈论选择,但属性名为activated。注意:还选择了一个不适用于我的问题的属性。嗯,我很困惑…我不明白。现在我已经将InternalFrameListener和FocusListener添加到所有JIF中,但这些侦听器中没有一个接收任何事件!我错了,我的听者现在可以工作了。但我想我会让整个事情变得不同。不过还是要谢谢你!