Java Swing JLabel, HTML and custom fonts

前端 未结 2 1283
旧巷少年郎
旧巷少年郎 2021-02-10 02:46

In our Java Swing application, we\'re loading a custom font and adding it to a JLabel:

try {
  this.font = Font.createFont(Font.TRUETYPE_FONT, new F         


        
相关标签:
2条回答
  • 2021-02-10 03:13

    To use some font:

    <html><head><style type="text/css">
    body { font-family: Cool; } </style></head><body>...
    

    The Font you created has to be registered first in the singleton GraphicsEnvironment to be accessible to all:

    GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    genv.registerFont(font);
    
    0 讨论(0)
  • 2021-02-10 03:17

    Because StyledDocument extends Document, you may be able use an implementation thereof using JTextField's setDocument() method.

    0 讨论(0)
提交回复
热议问题