在java中将输入对话框区域设置更改为希伯来语

时间:2014-09-22 11:23:52

标签: java swing locale joptionpane hebrew

我的申请是希伯来语。运行我的应用程序的计算机都将英语设置为默认语言,希伯来语作为辅助语言

每当他们需要向应用程序输入内容时,他们必须" alt + shift"改变语言。

在我的上一个问题中 - > Change input language in java 我对如何为文本字段设置语言环境有了一个很好的想法,并且它工作得很好!

现在我需要在所有弹出输入对话框中执行相同操作。

之前的解决方案基于使用JTextField FocusListener的FocusGained方法, 现在我没有FocusGained选项,至少据我所知:)

IE:

response = JOptionPane.showInputDialog(requestLine.this, ("<html><b><font color=\"#8F0000  +
  +   \"size=\"10\" face=\"Ariel\">" + "הכנס סטטוס חדש: " + "</font></p></html>"), "");

此选项窗格要求输入,并将其存储在字符串中,我需要它以准备输入希伯来语。

这甚至可能吗?

谢谢, 的戴夫

2 个答案:

答案 0 :(得分:1)

这会使showInputDialog与区域设置更改重复:

public class LocaleOptionPane extends JFrame {

    public static void main(String[] args) {

        new LocaleOptionPane();
    }

    LocaleOptionPane() {

        Locale loc = new Locale("iw", "IL");
        String message = "<html><b><font color=\"#8F0000\" size=\"10\" face=\"Ariel\">" + "הכנס סטטוס חדש: " + "</font></p></html>";

        setVisible(true);

        JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
        pane.setWantsInput(true);

        JDialog dialog = pane.createDialog(this, UIManager.getString("OptionPane.inputDialogTitle", loc));
        dialog.getInputContext().selectInputMethod(loc); // pane.getInputContext... also works
        dialog.setVisible(true);
        dialog.dispose();

        String response = (String) pane.getInputValue();
        if (response == JOptionPane.UNINITIALIZED_VALUE)
            System.out.println("aborted");
        else
            System.out.println(response);
    }
}

备注:

  • 我没有添加绿色问号图标,因为它看起来似乎不太合适,但可以通过将JOptionPane.PLAIN_MESSAGE更改为JOptionPane.QUESTION_MESSAGE来添加。
  • 您可以通过pane.createDialog来电更改标题。
  • 检查response
  • 的值时实现自己的行为
  • 更改父组件。

答案 1 :(得分:0)

public class MyDialog extends JDialog { private JTextField text = new JTextField(); public MyDialog() { //set this up with the text field and an "OK" button super(null); // ... } public String getValue() { return text.getText(); } }

然后在你的代码中......

MyDialog md = new MyDialog(); md.setModal(true); md.pack(); md.setVisible(true); // will block here until the dialog closes String val = md.getValue();