The JXTextField
extends JTextField
, so anything that works in a standard Swing text field should work in the JX
variant.
This problem likely comes down to support by the font used in the text field. The Arabic displays correctly here using the default font, but if it's not the same there, iterate the font families to find one that supports the text.
import java.awt.*;
import javax.swing.*;
public class ArabicInTextField {
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
String arabic = "عربي";
JTextField textField = new JTextField(arabic);
int result = JOptionPane.showConfirmDialog(
null, textField, "Does this show as expected?",
JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.NO_OPTION) {
String[] fontFamilies = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getAvailableFontFamilyNames();
for (String fontFamily : fontFamilies) {
Font font = new Font(fontFamily, Font.PLAIN, 20);
if (font.canDisplayUpTo(arabic) < 0) {
textField.setFont(font);
JOptionPane.showMessageDialog(
null, textField, fontFamily,
JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
};
SwingUtilities.invokeLater(r);
}
}
Here, 23 of around 250+ installed fonts (less than 10%) will display all characters of that string. Some of those fonts are logical fonts (they are mapped to a physical font at run-time, depending on the PLAF), so the true number is actually less.