JInternalFrame 最小化,同时保持当前位置
我需要 JInternalFrame 的可图标/最小化功能来折叠框架(它确实这样做),但也保持 JInternalFrame 在其父组件中的位置。目前,当我按下 JInternalFrame 的最小化按钮时,java 会将组件放置在其容器的底部。有没有办法在最小化的同时保持位置?如果没有明显的解决方案,我如何观察可图标图标并删除默认侦听器?谢谢。
I need the iconable/minimize feature of JInternalFrame to collapse the frame (which it does), but also maintain the JInternalFrame's position within its parent component. Currently, when I press the minimize button of a JInternalFrame, java places the component at the bottom of its container. Is there a way to maintain the location whilst minimizing? If there is no obvious solution, how might I observe the iconable icon and remove the default listener? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要修改此行为,您需要创建 javax.swing.DesktopManager 的实现。为了获得大部分可用的默认行为,我建议对 javax.swing.DefaultDesktopManager 进行子类化。
在 DefaultDesktopManager 中,方法
iconifyFrame(JInternalFrame f)
控制完整的行为,但在内部使用方法protected Rectangle getBoundsForIconOf(JInternalFrame f)
来确定正在使用的框架图标的边界最小化。您可以在此处返回要使用的内部框架图标的边界。问题是这些值被缓存,因此如果您希望它每次都移动,则需要执行如下操作。To modify this behavior you would want to create an implementation of
javax.swing.DesktopManager
. To get the majority of the default behavior already available I'd suggest subclassingjavax.swing.DefaultDesktopManager
.In DefaultDesktopManager the method
iconifyFrame(JInternalFrame f)
controls the complete behavior but internally uses the methodprotected Rectangle getBoundsForIconOf(JInternalFrame f)
to determine the bounds for the icon of the frame being minimized. Here you can return the bounds for the icon of the internal frame that you'd like to use. The problem is those values are cached so if you want it to move every time you would need to do something like the following.仅供记录,如果您想要的只是更改图标位置或大小,其他实现方法是通过 JInternalFrame 的internalFrameIconified() 事件:
这样,您可以为每个 JInternalFrame (或 JInternalFrame 类型)独立设置规则无需扩展 DefaultDesktopManager。不过,如果您想要普遍影响所有 JInternalFrames,我强烈建议您遵循 Joshua 建议。
Just for the record, if what you want is simply change the icon Location or Size, other way to achieve it is through the internalFrameIconified() event of your JInternalFrame:
This way, you can set rules independently for each JInternalFrame (or JInternalFrame type) without having to extend DefaultDesktopManager. However I will highly recommend to follow Joshua recommendation if what you want is to generally affect all JInternalFrames.