Como que eu faço para criar uma fonte a partir de um arquivo ttf.
Tenho uma fonte de código de barras, e quero que ela seja usada no meu sistema.
Fiz o seguinte código:
try {
File fl = new File(getClass().getResource("/recursos/fonte/CodaBarLarge.ttf").toURI());
Font f = Font.createFont(Font.TRUETYPE_FONT, fl);
f.deriveFont(Font.BOLD, 15f);
//Até aqui tudo funciona perfeitamente
txtFonte.setFont(f);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex);
}
Mas quando executo os componente do meu Frame não aparecem, só aparecem depois que ganham o foco!!! :shock:
Dêem um olhada no Stack Trace:
:shock: :?:
Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero
at javax.swing.text.PlainView.paint(PlainView.java:256)
at javax.swing.text.FieldView.paint(FieldView.java:171)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1422)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:722)
at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:869)
at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:848)
at javax.swing.JComponent.paintComponent(JComponent.java:751)
at javax.swing.JComponent.paint(JComponent.java:1017)
at javax.swing.JComponent.paintChildren(JComponent.java:852)
at javax.swing.JComponent.paint(JComponent.java:1026)
at javax.swing.JComponent.paintChildren(JComponent.java:852)
at javax.swing.JComponent.paint(JComponent.java:1026)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
at javax.swing.JComponent.paintChildren(JComponent.java:852)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5119)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1475)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1406)
at javax.swing.RepaintManager.paint(RepaintManager.java:1220)
at javax.swing.JComponent.paint(JComponent.java:1003)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1780)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Divisão por zero? Como asssim? como isso pode acontecer?
Se eu comentar a linha onde dou um setFont, tudo funciona perfeitamente…
Agradeço a ajuda!!!