1

I have downloaded the gohu font (which is programmer font meant to be used at 14pt) from here https://github.com/koemaeda/gohufont-ttf and I'm trying to display some text with it.

This is what it looks like in GIMP at 14pt (nice and sharp):

ok at 14pt in gimp

And now this is what I get when loading the font using PLAIN 14 in a JTextArea:

blurry in JTextArea

I've tried disabling anti aliasing with

((Graphics2D)(this.displayArea.getGraphics())).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

and

System.setProperty("awt.useSystemAAFontSettings","false");

but it didn't help. Any tips? Thanks

user2711115
  • 457
  • 3
  • 18
  • The first line of code won't work because `getGraphics()` returns brand new Graphics object each time it's called. I suspect this can only be solved by overriding the TextUI and the View, which is going to be ugly. – VGR Dec 19 '14 at 00:57
  • Thanks for the reply. Is there really no other way though? Basically what you're saying is that using non-antialiased fonts in java is a no go? :( – user2711115 Dec 19 '14 at 05:24
  • I ran a simple painting test and confirmed that the problem isn't Java; a straight graphics.drawString call uses the font's hints and draws text exactly as GIMP does. After some more searching, I happened upon [this](http://stackoverflow.com/questions/4805833/how-can-i-force-one-specific-jtextarea-to-not-use-anti-aliasing-while-keeping-i/4806023#4806023), which works perfectly—though the use of sun.* classes is at your own risk, since they are always subject to change or removal in future releases. – VGR Dec 19 '14 at 14:59
  • Thanks, I tried this.displayArea.putClientProperty(sun.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, null); but I can't compile:- Access restriction: The field 'SwingUtilities2.AA_TEXT_PROPERTY_KEY' is not API (restriction on required library '/xxx/jdk1.8.0_25/jre/lib/ rt.jar') - Access restriction: The type 'SwingUtilities2' is not API (restriction on required library '/xxx/jdk1.8.0_25/jre/lib/rt.jar') – user2711115 Dec 19 '14 at 16:59
  • That sounds like an Eclipse issue. (It works for me on the command line, using Java 1.7.0_72 and 1.8.0_25.) Perhaps [this](http://stackoverflow.com/questions/9266632/access-restriction-is-not-accessible-due-to-restriction-on-required-library), [this](http://stackoverflow.com/questions/860187/access-restriction-on-class-due-to-restriction-on-required-library-rt-jar) or [this](http://stackoverflow.com/questions/1089904/access-restriction-on-class-due-to-restriction-on-required-library) will help? – VGR Dec 19 '14 at 17:30

0 Answers0