Hebrew text in JTextField (Swing)

When I do something like fileText.setText(path)in JTextField, it works fine if the text is not in Hebrew (or combines English and Hebrew). Then I get something like this:

enter image description here

I tried different fonts (even fonts that mention "Hebrew"), but that didn't help. How to fix it?

By the way, it works correctly with ToolTipText ( fileText.setToolTipText(path))

Here is my code:

// browse files or folders
    public void browse(JTextField txtField) {

        JFileChooser fileChooser = new JFileChooser();

        fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));     

        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        int result = fileChooser.showOpenDialog(this);

        if (result == JFileChooser.APPROVE_OPTION) {
            File selectedDir = fileChooser.getSelectedFile();
            String path = selectedDir.getAbsolutePath();

            if (txtField == srcText) {
                srcText.setText(path); 
                srcText.setToolTipText(path); 
            }
            else {
                if (txtField == dstText) {
                    dstText.setText(path); 
                    dstText.setToolTipText(path);
                }
                }}
    }
+4
source share
1 answer

Not an answer, as your code works well as it is. Please try your environment.

For me, it works flawlessly out of the box with the default font in Windows 7. Java JDK1.8.0_31

public class JTextFieldExample extends JFrame {

    private static final long serialVersionUID = 1L;

    public JTextFieldExample() {
        super("TextField Test Demo");
        final Container container = getContentPane();
        final JTextField textField=new JTextField("hello \u05DD\u05D5\u05DC\u05E9 Hello \u05DD\u05D5\u05DC\u05E9"); 
        // optionally set RTL
        textField.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        container.add(textField);
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(final String args[]) {
        new JTextFieldExample();
    }
}

JTextField, :

hello םולש םולש

( , - . unicode , , "" ).

, . , - .

, RTL , , , , .

:

  • , JTextField ? , , , - .
  • , . , , . \-es
  • hexa. , , - Unicode.
+2

Source: https://habr.com/ru/post/1629588/


All Articles