[英]Hebrew text in JTextField (Swing)
當我在JTextField
執行類似fileText.setText(path)
的操作時,除非文本是希伯來語(或組合英語和希伯來語),否則它的效果很好。 然后我得到這樣的東西:
我嘗試了不同的字體(甚至在其中提到“希伯來語”的字體),但它沒有幫助。 我如何解決它?
順便說一下,它與ToolTipText( fileText.setToolTipText(path)
)一起正常工作
這是我的代碼:
// 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);
}
}}
}
不是答案,因為您的代碼運行良好。 請嘗試你的環境。
對我來說,它在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創建一個窗口:
你好,你好,祝賀你好
(我很抱歉,如果我在希伯來語中使用了一些奇怪或令人反感的東西。我只是從另一頁復制了unicode字符,他們聲稱這意味着“你好”)。
我也試過你在測試應用程序中的代碼,這也很好用。 也是希伯來語,英語 - 希伯來語混合物也很好用。
但是,您可能更喜歡將RTL方向設置為更好地匹配希伯來語,我想在我的示例中,希伯來字母以相反的順序顯示,而不考慮實際方向。
請執行下列操作:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.