I have already read this post but I am afraid it cannot help me, I do not know how to use java.text.Bidi
and most of all if it is suitable for me.
We are providing Arabic language support for out project and in addition to providing the relative translated properties files, I am adapting all Java Swing components so that they can manage input with Arabic Locale (the writing from right to left). This is the instruction I am executing for each of them:
private static final ComponentOrientation arabicOrientation = ComponentOrientation.getOrientation(new Locale("ar"));
/* ... */
component.applyComponentOrientation(arabicOrientation);
This seems to work fine for each component but for JTables. In fact, if a cell has mixed characters/words and when cell stop editing, then the original input words order is not respected and western words are showed before Arabic ones. For example:
Is this a standard and righr behaviour of Swing? Is that supposed to be showed like that?
When language is changed by user into another one, this is what is performed:
private static void adjustLanguageSettings() throws UnsupportedLookAndFeelException, ParseException {
//...
if("japanese".equals(language) || "chinese".equals(language) || "arabic".equals(language)){
UIManager.setLookAndFeel(...); //Look and Feel with Dialog font
} else {
UIManager.setLookAndFeel(...); //Look anf Feel with Verdana font
}
//for instanc: language = LANGUAGE.JAPANESE("japanese","ja","JP") or ARABIC("arabic","ar","")
if(language != null && LANGUAGE.lookUpByCode(language) != null){
LANGUAGE i = LANGUAGE.lookUpByCode(language);
Locale.setDefault(new Locale(i.getLanguage(),i.getCountry()));
JFileChooser.setDefaultLocale(Locale.getDefault());
}
}
So, the Locale should be Arabic everywhere. Finally, here are some code snippets of our TableCellRendered and TableCellEditor:
public class DefaultLabelCellRender extends JLabel implements TableCellRenderer, Serializable {
protected ColumnProperties properties;
private static final ComponentOrientation arabicOrientation = ComponentOrientation.getOrientation(new Locale("ar"));
/* ... */
public DefaultLabelCellRender(ColumnProperties properties) {
super();
setOpaque(true);
setBorder(getNoFocusBorder());
this.properties = properties;
this.applyComponentOrientation(arabicOrientation);
}
/* ... */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
/* ... */
this.applyComponentOrientation(arabicOrientation);
return this;
}
}
public class DefaultTextEditor extends AbstractCellEditor implements TableCellEditor,Observer {
private JTextField editor;
/* ... */
public Component getTableCellEditorComponent(JTable table, Object value, boolean isselected, int row, int col) {
/* ... */
this.editor = new JTextField(3)
/* ... */
this.editor.setText(text);
this.editor.applyComponentOrientation(arabicOrientation);
return (this.editor);
}
}
How can I solve this?