Swing:如何才能让 JInternalFrame 与容器内的其他组件受到同等对待?
背景信息:
我正在实现一个可视化图表编辑器,它由
- 不同的复杂元素(可调整大小,带标题栏,子元素)和
- 不同的简单元素(不可调整大小,无标题栏) 组成,没有子元素)。
所有元素都是可拖动的。
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能会误解你的问题。 您是否尝试过查看 JIF 的 setSelected() 方法? 似乎支持方法覆盖和可否决激活事件。
编辑:也许我们有一些术语误解,正如javadoc所述:
编辑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:
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.
在初始化 JInternalFrame= 时尝试一下,
请注意查看
JInternalFrame.setSelected(boolean)
中的代码,setSelected 和 'actvation' 在进程中绑定在一起,因为 setSelected 不仅会触发属性更改用于选择,还调用fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED)
。give this a try when you initialize your JInternalFrame=
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 callsfireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED)
as well.