println in Dialog with non-Latin symbol

71 views Asked by At

So I want to println in ACM library dialog with a symbol from a non-English language in Java, but when I run it, only little squares appear.

 IODialog dialog = getDialog();
 dialog.println("ზაზა");
1

There are 1 answers

0
demongolem On

IODialog uses JOptionPane for its implementation, therefore it is subject to the same unicode handling problems that JOptionPane has.

Here there is a way of overcoming the problem. But we don't like links so let me summarize:

As per the comment above, playing with fonts is what you want to explore. Create a new font like this:

public class MyFont {

/*

  Below code I extracted from

  http://www.java-forums.org/java-tips/6522-swing-changing-component-default-font.html

  then i customized it.

 */

public static void setUIFont (javax.swing.plaf.FontUIResource f){

java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
  Object key = keys.nextElement();
  Object value = UIManager.get (key);
  if (value instanceof javax.swing.plaf.FontUIResource)
    UIManager.put (key, f);
  }
}
}

and then you set the actual font with whichever font it is that contains your unicode characters with this line:

MyFont.setUIFont(new javax.swing.plaf.FontUIResource("Iskoola pota",Font.BOLD,18)); // setting the default font for application

So what this does is it changes your default font. There is no more you have to do. If you need to change back to your default font before you made the change, well you have to reset the default font in this way.