监听所有 JInternalFrame 事件 - Java

发布于 2024-08-08 09:57:49 字数 396 浏览 6 评论 0原文

我正在尝试国际化 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 技术交流群。

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

发布评论

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

评论(3

半枫 2024-08-15 09:57:49

将 ContainerListener 添加到 JDesktopPane。当组件添加到桌面时,您可以更改其方向。

Add a ContainerListener to the JDesktopPane. As a component is added to the desktop you can change its orientation.

沧桑㈠ 2024-08-15 09:57:49

您掌握所有这些 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.

哀由 2024-08-15 09:57:49

当前 Toolkit 上的 AWTEventListener 只会向您提供来自工具包的事件。通常,轻量级组件生成的事件是由鼠标或按键事件引起的。

在一个过程中要求所有的东西通常是一个非常糟糕的迹象。一段低级代码正在为整个程序制定策略。更好的方法是在“实现”组件之前在您创建组件的位置附近添加侦听器。这是重复的代码,但是您可能已经有了重复的代码。因此,将其分解为一个方法。那么你只有一个地方可以更新,除非你有任何不适用的情况,这会破坏全局方法。

AWTEventListener on the current Toolkit 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.

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