我的申请是希伯来语。运行我的应用程序的计算机都将英语设置为默认语言,希伯来语作为辅助语言
每当他们需要向应用程序输入内容时,他们必须" 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>"), "");
此选项窗格要求输入,并将其存储在字符串中,我需要它以准备输入希伯来语。
这甚至可能吗?
谢谢, 的戴夫
答案 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();