2017-12-30 9 views
1

javafx 레이블에 문제가 있습니다. 어떤 폰트를 아래의 폰트 생성자에 입력하든, IntelliJ 프로젝트를 컴파일하고 실행해도 디스플레이 된 폰트는 변경되지 않습니다. 글꼴 이름이 변경되지 않는 이유는 무엇입니까? (Java FX)

mainLabel.setFont(new Font("Gotham",18)); 

여기에 지금까지 내 자바 FX 프로그램입니다 : 나는 자신있게 선 mainLabel.setFont(new Font("Gotham",18));을 변경하면 실제로 적어도 내 환경 (BlueJ의)에서 표시 글꼴을 변경 않는 것을 확인할 수 있습니다

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Label; 
import javafx.scene.layout.FlowPane; 
import javafx.stage.Stage; 
import javafx.scene.text.Font; 


public class JavaFXMainWindow extends Application { 


    public static void main(String args[]) { 


     launch(args); 
    } 


    public void init() { 


    } 


    //Program starts here 
    public void start(Stage mainStage) { 

     //Setting the stage 
     mainStage.setTitle("Ping Tool"); 
     mainStage.setResizable(false); 
     mainStage.setFullScreen(false); 


     //Creating the root node for all other nodes 
     FlowPane rootNode = new FlowPane(); 


     //Setting the main scene, adding the root node to it and passing dimensions 
     Scene mainScene = new Scene(rootNode, 1000, 800); 

     //placing the scene on the stage 
     mainStage.setScene(mainScene); 

     //Setting a label (no matter what argument I pass to the font it still 
     //shows the same font. The size argument works fine though) 

     Label mainLabel = new Label("Please enter IP addresses below:"); 
     mainLabel.setFont(new Font("Gotham",18)); 

     //Adding the node to the tree 
     rootNode.getChildren().addAll(mainLabel); 

     //making the Stage visible 
     mainStage.show(); 
    } 


    public void stop() { 


    } 


} 
+1

글꼴은 지정된 이름으로 시스템에 존재하지 않을 수도 있고 JVM이이를로드 할 수 있도록 설치되지 않았을 수도 있습니다. 'Font.getFontNames()'를 사용하여 사용 가능한 모든 글꼴 이름을 나열 할 수 있습니다.이 목록을 먼저 확인하여 사용 가능한지 확인합니다. 내 시스템에서'Gotham'은 나열되어 있지 않습니다. – MadProgrammer

답변

0

. 업데이트 된 .class 파일을 사용하도록 컴파일하려고합니까?

+1

이제 모든 코드를 새 프로젝트로 옮기고 테스트를 마쳤습니다. 이제 작동 중입니다. 프로젝트 구조에 잘못된 것이 있었을 것입니다. 확인해 주셔서 고마워요. D (2 시간 동안 초보자로서 제 코드가 문제라고 생각했습니다.) –

+0

이상한! 무엇이 잘못되었는지 보았을 때 같은 오류가 발생했을 때 글꼴은 바뀌지 않았습니다. IntelliJ를 다시 시작했는데 마술처럼 작동하기 시작했습니다. 이상한 사람! –

0

이전에는 글꼴과 비슷한 문제가있었습니다. 내 글꼴이 시스템에 설치되지 않았습니다. 이 후에 한 가지 더해야만했습니다. 프로젝트를 다시 빌드하여 응용 프로그램 캐시를 새로 고칩니다. 이 문제가 해결되었습니다. 당신은 실제로 당신이 말하는 인수를 누락

0

... 나는 그것이 이렇게 될 전망이다

mainLabel.setFont(new Font("Gotham",18)); 

,

Panel panel = new Panel(); 
Graphics g = panel.getGraphics(); 

Font myFont = new Font("Calibri", Font.PLAIN, 24); 
g.setFont(myFont); 

참고 Font.PLAIN, Font.BOLD은 어떻게해야 트릭뿐만 아니라 전체 패널을 변경합니다!

그래픽 클래스를 적절하게 가져 오는 것을 잊지 마십시오.

+0

잘못된 API를보고 있습니다. 이것은 JavaFX 질문입니다. 문제의'Font'는'javafx.scene.text.Font'입니다. JavaFX에는'Panel' 클래스가 없습니다. –

+0

아, 그게 사실 꽤 당황 스럽네요 ... –

+0

챕 스 걱정하지 마세요, 우리는 모두 여기서 배우고 있습니다. –

관련 문제