简体   繁体   English

Java中的字体问题

[英]Font Problems in Java

Here's my question. 这是我的问题。

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. 我正在将ttf字体加载到Java中,并且我知道它正在读取它是因为它不会给我一个错误,但是它不会真正读取该字体,因为它只会给我一行。

Here's the code for my Screen class that uses the font: 这是我的使用字体的Screen类的代码:

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. 我不知道为什么只给我一行,但这是事实。

Font#createFont返回Font#createFont的字体...您应将结果分配给Font变量,并使用Font#deriveFont指定大小和样式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM