I usually try not to ask questions that I've seen before, but this is different. I've been trying to get my custom font to work, but whenever I try to use it in a method, I get the error "Cannot make a static reference to the non-static method". I know what that means, but I'm not sure how to fix it. Here's the example -
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.io.InputStream;
public class AddFont extends MainFrame{
public void createFont() throws Exception {
InputStream telegraficoFontAdd = AddFont.class.getResourceAsStream(FONT_PATH_TELEGRAFICO);
Font telegraficoFont = Font.createFont(Font.TRUETYPE_FONT,telegraficoFontAdd);
telegraficoFont = telegraficoFont.deriveFont(Font.PLAIN,20);
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(telegraficoFont);
}
}
That's my AddFont class file, here is the snippet of my MainFrame -
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
AddFont addFont = new AddFont();
addFont.createFont();
} catch (Exception e) {
e.printStackTrace();
}
createGUI();
} //public void run() Closing
});
}
How would I find a way to use the method class in static objects, because I have a long list of buttons I need to change the fonts for? Or is there some work-around that I must do?
And as always, if you downvote this, please tell me why, so I will know how to improve. Hopefully this is considered an SSCCE.
EDIT - Changed my main method in my MainFrame, now I get the error -
java.io.IOException: Problem reading font data.
at java.awt.Font.createFont(Unknown Source)
at AddFont.createFont(AddFont.java:11)
at MainFrame$1.run(MainFrame.java:107)
(Line 11 in my AddFont file is this -
Font telegraficoFont = Font.createFont(Font.TRUETYPE_FONT,telegraficoFontAdd);
and Line 107 of my MainFrame is
addFont.createFont();