Olá! Durante o desenvolvimento do meu TCC, lembrei de um detalhe que é a falta das fontes do Windows no Linux.
Então resolvi tentar fazer a importação de uma font no diretório do projeto. Demorei achar uma solução, porém, existem dois detalhes que são graves.
Primeiro: Se eu quiser mudar o tamanho da fonte, terei que fazer outro método.
Segundo: Se existem 50 Labels, terei que ir em uma por uma e alterar utilizando .setFont()…
Classe da fonte:
public class fontManager {
Font fonte;
public Font font() throws MalformedURLException, IOException, FontFormatException {
URL fontUrl = new URL("file:fonts/OpenSansCondensed-Bold.ttf");
fonte = Font.createFont(Font.TRUETYPE_FONT, fontUrl.openStream());
fonte = fonte.deriveFont(Font.PLAIN, 20);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(fonte);
return fonte;
}
}
Form onde seriam aplicadas:
public NewJFrame() throws IOException, MalformedURLException, FontFormatException {
initComponents();
fontManager ftn = new fontManager();
Font f = ftn.font();
jLabel1.setFont(f);
}