监听所有 JInternalFrame 事件 - Java
我正在尝试国际化 Java 小程序,并支持从右到左编写的脚本。我想为自动添加到视图中的所有 java 组件设置组件方向。
到目前为止,我的解决方案必须使用窗口掩码侦听所有 AWTEvent:
c.getToolkit().addAWTEventListener(listener, AWTEvent.WINDOW_EVENT_MASK);
...然后在添加的每个窗口上设置 c/o,以及添加组件侦听器以在添加到窗口的任何组件上设置 c/o稍后一点。
我的问题是这个解决方案不处理 JInternalFrames,我希望能够为这些事件添加另一个侦听器,就像我为 Windows 所做的那样。有什么想法吗?
或者,是否有更好的方法来处理小程序中所有组件的脚本方向?
I'm trying to internationalise a Java applet and with that, support scripts which are written from right to left. I want to set up component orientations for all java components added to the view automatically.
My solution so far has to listen to all AWTEvent's using the windows mask:
c.getToolkit().addAWTEventListener(listener, AWTEvent.WINDOW_EVENT_MASK);
...and then setting the c/o on each window added, as well as adding component listeners to set c/o on any components added to the window at a later point.
My issue is that JInternalFrames are not handled by this solution, I want to be able to add another listener for these events, much like I have done for windows. Any ideas?
Or alternatively, are there any better approaches to handling script direction for all components in an applet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 ContainerListener 添加到 JDesktopPane。当组件添加到桌面时,您可以更改其方向。
Add a ContainerListener to the JDesktopPane. As a component is added to the desktop you can change its orientation.
您掌握所有这些 JInternalFrames 吗?如果是这样,请尝试内部帧侦听器。
http://java.sun.com/ javase/6/docs/api/javax/swing/event/InternalFrameListener.html
它指出它与 AWT WindowListener 类似。
Do you have a handle on all those JInternalFrames? If so, try the internal frame listener.
http://java.sun.com/javase/6/docs/api/javax/swing/event/InternalFrameListener.html
It notes that it's the analogue to the AWT WindowListener.
当前
Toolkit
上的AWTEventListener
只会向您提供来自工具包的事件。通常,轻量级组件生成的事件是由鼠标或按键事件引起的。在一个过程中要求所有的东西通常是一个非常糟糕的迹象。一段低级代码正在为整个程序制定策略。更好的方法是在“实现”组件之前在您创建组件的位置附近添加侦听器。这是重复的代码,但是您可能已经有了重复的代码。因此,将其分解为一个方法。那么你只有一个地方可以更新,除非你有任何不适用的情况,这会破坏全局方法。
AWTEventListener
on the currentToolkit
will only give you events coming from the toolkit. Generally events generated by lightweight components will have been caused by mouse or key events.Asking for all of something in a process is usually a very bad sign. A low-level piece of code is making policy for the whole program. A much better approach is to add listeners near to where you create the component, before it is "realised". This is repeated code, but then you probably already have repeated code. So factor out into a method. Then you have only one place to update, unless you have any cases where it doesn't apply which would have broken the global approach.