views:

263

answers:

3

Hi,

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?

Thanks.

A: 

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.

M1EK
Thanks - I do kind of but would rather not since there are 83 usages when doing a quick search...I would rather just do it all in one place.
Ed
A: 

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.

Tom Hawtin - tackline
A: 

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

camickr
I already had this but thought it wasn't working...I now realise it was another issue that was causing problems. Thanks anyway.
Ed