Reputation:
I'm loading up a ttf
font into Java, and I know it's reading it because it doesn't give me an error, but it won't REALLY read the font, because it simply presents me with a line.
Here's the code for my Screen class that uses the font:
public class BLANKMainMenuScreen extends JPanel {
private JButton playButton;
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = d.width;
int screenHeight = d.height;
public ImageIcon greenButton = new ImageIcon("resources/menubuttons/GreenButton.png");
public ImageIcon redButton = new ImageIcon("resources/menubuttons/RedButton.png");
public BLANKMainMenuScreen() throws FontFormatException, IOException {
setLayout(new GroupLayout(this));
playButton = new JButton("Play!");
playButton.setIcon(greenButton);
playButton.setBorderPainted(false);
playButton.setContentAreaFilled(false);
playButton.setFocusPainted(false);
playButton.setActionCommand("/mainMenuPlayButton");
playButton.setFont(Font.createFont(Font.TRUETYPE_FONT, new File("resources/font/cubic.ttf")));
playButton.setBounds(screenWidth / 2 - 100, screenHeight / 3 - 50, 200, 100);
playButton.setRolloverEnabled(true);
playButton.setRolloverIcon(redButton);
playButton.setHorizontalTextPosition(SwingConstants.CENTER);
add(playButton);
}
public void addActionListener(JButton b, ActionListener listener) {
b.addActionListener(listener);
}
public void removeActionListener(JButton b, ActionListener listener) {
b.removeActionListener(listener);
}
@Override
public Dimension getPreferredSize() {
return Toolkit.getDefaultToolkit().getScreenSize();
}
I don't know why it would be presenting me with just a line, but it is.
Upvotes: 0
Views: 58
Reputation: 347184
Font#createFont
returns a font of 1pt...you should assign the result to a Font
variable and use Font#deriveFont
to specify a size and style
Upvotes: 1