Java AWT PopupMenu 韩语/亚洲字符不显示



我被要求将韩语、中文和日语纳入我的程序,事实证明这很困难。由于TrayIcon的问题,我被迫使用AWT而不是Swing,但是AWT PopupMenu似乎拒绝完全识别亚洲字符。

下面是演示该问题的示例程序:

package awttest;
import java.awt.*;
import java.awt.event.ActionEvent;
public class AWTTest
{
public static void main( String[] args )
{
Frame frame = new Frame( );
frame.setSize( 400, 300 );
frame.setLayout( new FlowLayout( ) );
Button button = new Button( "Test" );
button.addActionListener( ( ActionEvent e ) ->
{
PopupMenu popup = new PopupMenu( "Menu" );
MenuItem item = new MenuItem( "uc2dcuba54uc9c0" );
popup.setFont( new Font( "Serif", 0, 12 ) );
System.out.println( popup.getFont( ).canDisplay( 'uc2dc' ) ); // prints true
popup.add( item ); // displays 3 boxes
popup.add( new MenuItem( "English Text" ) ); // displays normally
button.add( popup );
popup.show( button, 0, 25 );
} );
frame.add( button );
frame.setVisible( true );
}    
}

我尝试将字体设置为韩语支持的Windows字体之一,例如Gulim或Dotum,但我有相同的结果。即使将计算机的区域设置更改为韩国也没有效果。有没有办法让AWT弹出菜单支持亚洲字符?

你的程序对我有用。 我在跑步

$ java -version
openjdk version "1.8.0_172"
OpenJDK Runtime Environment (build 1.8.0_172-b11)
OpenJDK 64-Bit Server VM (build 25.172-b11, mixed mode)

在 Fedora 27 上。

至少,这表明问题不在您的代码中。这可能是一个配置问题...


我建议你看看这两个Oracle资源,看看你自己的系统与它们所说的之间是否存在差异:

  • 支持的字体
  • 字体配置文件

最新更新