views:

976

answers:

4

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.

+2  A: 

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);
            }
        });
    }
}
kdgregory
My operating system is Windows XP. I already tried changing my active title bar to a different font, but it did not change the font of the title bar.
baseballtank13
Updated at the same time you commented -- are you sure that the font you selected has the glyphs for the characters you're using? Test by setting that font face on a Swing label. It's also possible you'll need to do something Windowsish like rebooting.
kdgregory
Both of those ideas did not work. Is there a line like this i could use...UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("Dialog", Font.PLAIN, 11)));... for main title?
baseballtank13
I suspect that your font simply doesn't support the glyph. When I tried running the above on XP, I got the "unsupported box" in both the title and the label.
kdgregory
That showed the character correctly
baseballtank13
"A window's title bar is managed by the system window manager, not by Swing." Not true. A Look-and-Feel can override all the Window decorations, including the font of the title bar.
banjollity
If the look-and-feel can override it, how can I change the font of a look-and-feel title bar?
baseballtank13
kdgregory
@Greg - when I ran the above program at home on my Linux box, it displayed the character in the title bar (but not, surprisingly, in the label). I really think that your problem is that you have a font that doesn't support the glyph.
kdgregory
This comes back to my original question of how do I change the font in the title bar area in this situation to one that supports the glyph.
baseballtank13
I don't think the problem is changing the font, I think it's ensuring that your desired font has the glyph(s) that you need. You're not going to find a font that supports the entire Unicode character set. Windows fonts, in particular, seem to be very limited (I've had numerous cases where text rendered correctly on Linux but not Windows). That was the point of my example program (although I didn't make that clear): if you could set a font that rendered the label correctly, you should be able to use the same font for the title bar (and could verify that the control panel would let you do this).
kdgregory
Ultimately, I think you're going to have to search through the installed fonts to find one that does what you need. There's probably an MSDN tool that will show all glyphs in a font, or you could probably use Word. Or a Google search like "what Windows fonts support Katakana," but I suspect that you'll get overwhelmed by forum postings where people ask the same question.
kdgregory
I know which fonts I would like to use that support all the glyphs I need. But the issue is changing it to one of those fonts. I do not think we are on the same page. I know the font I want, but I do not know how to change title bar font with Java!
baseballtank13
I can't help you with that; perhaps @banjollity can, if s/he ever reads this post again, but more likely you'll need to write JNI. But I still contend that it's an issue with the font not containing glyphs: I was able to change the title bar font via the control panel, and it updated my Java apps along with everything else. Perhaps your XP is different from my XP.
kdgregory
Hi folks! Read this: http://www.java2s.com/Tutorial/Java/0240__Swing/SpecifyingWindowDecorations.htm
banjollity
A: 

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.

banjollity
This did not work. It did not change anything.
baseballtank13
Always a good idea to test things before posting them ... didn't work for me, and when I grepped the 1.5 source for that attribute, I didn't find it.
kdgregory
I think I figured out more of what the problem is (not closer to the solution unfortunately). Calling ...JFrame.setDefaultLookAndFeelDecorated(true);JDialog.setDefaultLookAndFeelDecorated(true);with substance look and feel is why it is not showing japanese font. If you comment out these two lines, you can see the japanese characters, but the problem is that the title bar is its usual blue instead of being the color of the theme (I have to have the color of the theme in the title bar.).
baseballtank13
A: 
JFrame.setDefaultLookAndFeelDecorated(true);
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.put( "InternalFrame.titleFont", Resources.jaDefault.deriveFont(16.0f) );

Try it ;)
A: 

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:

  1. On the Windows Start menu, open the Control Panel.
  2. Click the Regional and Language Options icon, and then click the Languages tab.
  3. In the Supplemental languages support box, check the box for Install files for East Asian languages.
  4. Click Apply and OK.
Brad C