问题
I am able to display Japanese characters everywhere except for the title bar of the main window (JFrame) in Java. Is there a way to change the font of this title bar so it can display japanese characters? Thanks
I am using Windows XP. If this matters I am using the Java Substance look and feel too.
回答1:
A window's title bar is managed by the system window manager, not by Swing. You don't say what OS/GUI you're using.
For Windows XP, open the Display control panel, select the "Appearance" tab, and click the "Advanced" button; you can change the title font there (although the fonts installed on your system may not have the glyphs you need).
Here's some code that checks whether the system default font supports the glyph that you want (I have no idea what the character is; it's a nice-looking glyph from the Katakana set):
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class GlyphCheck
{
public static void main(String[] argv) throws Exception {
final String title = "Testing: \u30CD";
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel label = new JLabel(title);
label.setSize(200, 100);
frame.setContentPane(label);
frame.pack();
frame.setVisible(true);
}
});
}
}
回答2:
JFrame.setDefaultLookAndFeelDecorated(true);
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.put( "InternalFrame.titleFont", Resources.jaDefault.deriveFont(16.0f) );
Try it ;)
回答3:
In order to override the font of the Frame you need to tell the look and feel to take care of its appearance. This may or may not be desirable, but you'll be at the mercy of the system otherwise. Some look and feels have quite good window decorations, others not so. Substance's are okay. Tell the UIManager what font to use also.
// Do this before you display any JFrame.
UIManager.put( "Frame.font", new Font( "Japanese", 12, Font.PLAIN ) );
JFrame.setDefaultLookAndFeelDecorated( true );
JFrame frame = new JFrame( title );
This approach (should it work - not tested it sorry!) will mean you'll be able to distribute your program without telling users that they need to change their Windows settings, as per the other answer.
回答4:
I'm not familiar with Java Substance, but I experienced this when working on a webapp. Basically the Japanese, Chinese and Korean characters would show in the content in the page, but not in the browser title bar.
This is due to the fact that the windowing system controls this title bar, not the browser. Based on kdgregory's comment, it sounds like this is a similar situation to yours.
For the windowing system to understand the characters and not show the unsupported 'box' you have to ensure the proper character sets are installed. For Windows XP, the following steps resolved the problem with the browser title bar:
- On the Windows Start menu, open the Control Panel.
- Click the Regional and Language Options icon, and then click the Languages tab.
- In the Supplemental languages support box, check the box for Install files for East Asian languages.
- Click Apply and OK.
来源:https://stackoverflow.com/questions/936123/showing-japanese-characters-in-title-bar-of-java-program