ComponentOrientation and Right To Left Languages
By Adrian Sutton
For some time, we’ve had an Arabic translation in EditLive! and the editor pane itself fully supports bidirectional text, but we’ve never updated the UI to flip over to a mirror image when a right to left language is in use. Java actually has pretty reasonable support for this via the ComponentOrientation property in AWT (and inherited through to Swing) but there are a couple of annoying limitations:
- It applies on a per component basis, so there isn’t a single place you can apply the orientation and be done with it.
- Various components still don’t flip, eg JSplitPane.
- The Aqua L&F on OS X has some annoying bugs when in right to left mode.
For the first issue, you can use applyComponentOrientation which will automatically traverse the component hierarchy and make the changes but it still misses things like combo box renderers, dialogs or components that are generated later. For an application that loads its UI incrementally instead of blocking the swing thread while it loads in one go this is a significant annoyance. Even beyond that, all the dialogs need to be updated as well. While it is good that you can override the orientation on a per-component basis, it seems more intelligent to have a simple way to change the default value in one place without all the work.
The second issue really just means more special case code to deal with which is a shame. In some cases you just need to change the way you use the classes like using LINE_START and LINE_END instead of EAST and WEST with BorderLayout, in others you really need special case code.
The bugs in the Aqua L&F are annoying – editable JComboBoxes are probably the worst, the text field winds up aligned right but the combo drop down button stays on the right so they overlap. The new capsule button styles that are applied by client properties don’t handle right to left either so you have to manually track the component orientation and flip the “first” to “last” and visa versa.
All that said, supporting right to left languages is never just a flick of the switch and I’m yet to really get into the details of how it all should work (this was just an afternoon’s investigation) so Java’s done a pretty good job at supporting it and getting things this far. It will be interesting to hear from people who actually speak Arabic and get their feedback about how it should work and where all the little details we need to take care of are. If you happen to be an Arabic EditLive! user, please get in touch, it would be great to get some individual feedback before we roll out an update to everyone.