2012-01-23 3 views
12

javafx-2에서 TextArea의 배경과 텍스트 색상을 변경하려고 설정했습니다.JavaFX-2 - 여러 스타일을

myComponent = new TextArea(); 
    myComponent.setStyle("-fx-text-fill: white;"); 
    myComponent.setStyle("-fx-background-color: black;"); 
    myComponent.setStyle("-fx-font: " + GUIConstants.SysResponseFont.getName()); 
    myComponent.setStyle("-fx-font-family: " + GUIConstants.SysResponseFont.getFamily()); 
    myComponent.setStyle("-fx-font-size: " + GUIConstants.SysResponseFont.getSize()); 
    myComponent.setStyle("-fx-font-weight: " + GUIConstants.SysResponseFont.getStyle()); 

이 TextArea에는 색상이나 글꼴이 설정되지 않습니다. 다른 접근법을 사용해야합니까?

답변

19

후자의 setStyle()은 이전 것보다 우선합니다. 다음 코드는 여러 스타일을 설정합니다 :

myComponent.setStyle("-fx-text-fill: white;"+ 
    "-fx-background-color: black;"+ 
    "-fx-font: Courier New;"+ 
    "-fx-font-family: Courier New;"+ 
    "-fx-font-weight: bold;"+ 
    "-fx-font-size: 30;"); 

난 당신의 코드에 대한 추측은 것 니펫을 :

myComponent = new TextArea(); 
myComponent.setStyle(
    "-fx-text-fill: white;"+ 
    "-fx-background-color: black;"+ 
    "-fx-font: " + GUIConstants.SysResponseFont.getName()+ ";" + 
    "-fx-font-family: " + GUIConstants.SysResponseFont.getFamily()+ ";" + 
    "-fx-font-size: " + GUIConstants.SysResponseFont.getSize()+ ";" + 
    "-fx-font-weight: " + GUIConstants.SysResponseFont.getStyle());   

주 라인의 끝에 ; 표지판입니다.

+0

감사합니다. 지금이 상태는 합리적입니다. :) – Rouby

관련 문제