stuie382 / jsyntaxpane

Automatically exported from code.google.com/p/jsyntaxpane
0 stars 0 forks source link

changing font? #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
very useful component, thanks.

how can i change the font family used?  i've tried using setFont() and
setting the component to honour the properties, but it just makes the
spacing bigger.

Original issue reported on code.google.com by andrew.m...@gmail.com on 19 Jun 2008 at 1:31

GoogleCodeExporter commented 9 years ago
You need to change the SyntaxStyles class.  The createInstance method sets the
different fonts and colors for each TokenType.  The SyntaxStyle class has the 
fonts
to use in the createFont method.  It uses Courier 12 by default.

I'll probably try and find a way to use the font from the component.  But that 
may
take time.  The other reason I did not implement this, is that I may need to 
change
the font for each TokenType, not just color, bold and italic.

Original comment by ayman.al...@gmail.com on 21 Jun 2008 at 5:40

GoogleCodeExporter commented 9 years ago
Also check the SyntaxStyle constructor that takes a font as an argument.  This 
is
added in 0.2 release.

Original comment by ayman.al...@gmail.com on 21 Jun 2008 at 5:48

GoogleCodeExporter commented 9 years ago
i've shadowed the syntaxstyles class for the moment.  i've just removed any 
setFont
calls in it -- it uses the one set on g2d, and hence the component.

Original comment by andrew.m...@gmail.com on 21 Jun 2008 at 4:00

GoogleCodeExporter commented 9 years ago
I'm able to set the font by doing JEditorPane.setFont() but it isn't consistent 
different fonts.  For example changing to Lucida Console which is supposed to 
be fixed-
width loses its width once in a number sequence which is apparently bold.  I'd 
expect 
that fixed-width fonts would always work but that is not true.  Maybe there is 
a bold 
highlighting of certain types?  Is that true?

Original comment by wadezieg...@gmail.com on 6 Mar 2010 at 5:13

GoogleCodeExporter commented 9 years ago
After a brief but hilarious foray into the source code, I have stumbled upon 
some marvelous undocumented code. Set the "DefaultFont" property to the font 
name followed by the size eg.

    DefaultSyntaxKit.initKit()
    // override default syntax values
    Configuration config = DefaultSyntaxKit.getConfig(DefaultSyntaxKit.class);
    config.put("DefaultFont","monospaced 14");

Original comment by benneybopper on 6 Feb 2013 at 10:39

GoogleCodeExporter commented 9 years ago
This is a good trick. Monospaced is a much better default than Courier, because 
it will automatically pick the right monospaced font for the platform.

Original comment by trejkaz on 6 Jul 2014 at 3:43