1

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("ზაზა");
Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • 1
    What is `IODialog`? Post your `getDialog` method – Reimeus Jan 05 '14 at 16:22
  • @Reimeus I think this : http://www-cs-faculty.stanford.edu/~eroberts/jtf/javadoc/student/acm/io/IODialog.html – user2336315 Jan 05 '14 at 16:22
  • yes I mean http://www-cs-faculty.stanford.edu/~eroberts/jtf/javadoc/student/acm/io/IODialog.html – user3151874 Jan 05 '14 at 16:35
  • 1
    Ok, There is no difference between, there is written getDialog() or new IODialog(); – user3151874 Jan 05 '14 at 16:43
  • Always tag your questions with acm-java-libraries when you are using the ACM Java Libraries. Ordinary Java programmers have never heard of them and will be very puzzled if you don't. They are only used in educational settings I think. – Robin Green Jan 05 '14 at 19:14
  • as to your question, my guess is that it's a font issue. You would need to make it use an appropriate font that is able to display such text, I think. – Robin Green Jan 05 '14 at 19:15

1 Answers1

0

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.

demongolem
  • 9,474
  • 36
  • 90
  • 105