0

Why can't I switch input language in jtextfield and JOptionPane.showInputDialog()? On my computer I can, but on other computer I can write only system locale language symbols.

Ctrl+Shift or Ctrl+Alt+Shift is not working in application, but it is working when app is not focus

Locale.setDefault(Locale.ENGLISH); //tried it
System.setProperty("user.language", "en"); // and it

private void showPasswordWindow() {

    String pass = JOptionPane.showInputDialog(null, "Enter password", "Secure", JOptionPane.WARNING_MESSAGE);
    if (pass == null)
        System.exit(0);
    if (!pass.contains("somepassword"))
        showPasswordWindow();
}

Not working (( password contain English symbols and I can't to enter password (only Russia symbols working)

JRE 8; PS: I want to enter English symbols, but I can type only Russian symbols...NOT WORKING ONLY DIALOG TEXTFIELDS

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Suleiman
  • 1,003
  • 2
  • 15
  • 29

3 Answers3

0

You should change the Locale:

textField.getInputContext().selectInputMethod(Locale.ENGLISH);

EDIT

Maybe it's not the best option, but you can try override the default DocumentFilter for the JtextField and change the encoding:

class EnglishTextField extends JTextField {

    public EnglishTextField() {
        ((AbstractDocument)getDocument()).setDocumentFilter(new DocumentFilter(){
            @Override
            public void insertString(DocumentFilter.FilterBypass fb, int offset,
                    String text, AttributeSet attr) throws BadLocationException {
                try {
                    //TODO change to your current encoding
                    byte[] bytes = text.getBytes("ISO-8859-1"); 
                    fb.insertString(offset, new String(bytes, "UTF-8"), attr);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
elias
  • 15,010
  • 4
  • 40
  • 65
0

There are two issues here.

The first is entering the symbols. This isn't really a Java problem, so much as an issue with installing a different language for the keyboard.

The second issue is displaying foreign language symbols. You may need to use a UTF font to display characters that otherwise don't display right

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
0

Finally...i did it O_O

frame.setVisible(true);

solved the problem, but i can't understand why??..

p.s. without the code on my comp app working nice

Suleiman
  • 1,003
  • 2
  • 15
  • 29