Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top