开发者

Listening to all JInternalFrame events - Java

I'm trying to in开发者_运维知识库ternationalise 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?


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜