2
JLabel 내에 사용자 정의 글꼴을 표시하려고하는데 작성시 매우 작은 텍스트로 표시됩니다. 나는 텍스트가 너무 작기 때문에 내가 지정한 글꼴을 사용하고 있는지 알지 못한다. 여기에 the font that I used입니다. 그래서 제가 글꼴을 너무 작게 만드는 것입니까?사용자 정의 JLabel 글꼴이 너무 작습니다.
package sscce;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main extends JFrame{
public Main(){
this.setSize(300, 300);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GameFont fnt = new GameFont("/home/ryan/Documents/Java/Space Shooters/src/media/fonts/future.ttf", 20);
Label lbl = fnt.createText("Level 1 asdf sadf saf saf sf ");
this.add(lbl);
}
public static void main(String[] args){
Main run = new Main();
}
public class GameFont{
protected Font font;
public GameFont(String filename, int fontSize){
try{
File fontFile = new File(filename);
font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
font.deriveFont(fontSize);
}catch(FontFormatException | IOException e){
}
}
public Label createText(String text){
Label lbl = new Label(font);
lbl.setText(text);
return lbl;
}
}
public class Label extends JLabel{
public Label(Font font){
this.setFont(font);
}
}
}
그래서 저는 이것을 float로 변경했고, 여전히 작습니다. –
@RyanNaddy : 편집을 참조하십시오. deriveFont 메소드로부터 돌려 주어진 Font를 사용할 필요가 있습니다. –
좋습니다. 감사! 변수를 재 할당하지 않았습니다! –