2015-02-04 2 views
0

JavaFX에서 CSS를 통해 Skin을 정의하는 올바른 위치는 무엇입니까? 매우 간단한 사용자 지정 컨트롤이 있다고 가정 해 봅시다.JavaFX에서 CSS를 사용하여 스킨을 전환하려면 어떻게해야합니까?

컨트롤의 기본 스킨을 지정할 수 있다는 것을 알고 있습니다. 나는 한 가정 ActionLinkSkin ... 내가 createDefaultSkin()를 사용하지 않는 경우

@Override 
protected Skin<?> createDefaultSkin() { 
    return new ActionLinkSkin(this); 
} 

, 나는 피부를 나타내는 SEVERE 경고를 찾을 수없는 경우를 참조 :

The -fx-skin property has not been defined in CSS for [email protected] \ 
    and createDefaultSkin() returned null. 

우선, 난 컨트롤의 CSS가 어디에 속하는지 확실하지 않습니다. 컨트롤 용 스타일 시트 action-link.css을 사용해야합니까, 아니면 스킨 용 스타일 시트를 사용해야합니까? action-link-skin.css? 나에게 그것은 피부와 CSS가 상당히 상호 의존적 인 것처럼 보이지만, 컨트롤을위한 스타일 시트를 사용하는 것이 더 보편적 인 것처럼 보인다.

둘째, 그리고 내 주요 문제는 정확히 어디서 정의되었는지 알 수 없으므로 -fx-skin입니다.

이제 CSS를 올바르게 설정했다고 가정하면 대체 스킨을 포함하고 싶다면 ActionLinkButtonSkin? 부모 구성 요소가 CSS를 통해 스킨을 선택할 수 있도록 설정하는 방법이 있습니까?

.action-link { 
    -fx-skin: "ActionLinkSkin"; 
} 

... 나 : 예를 들어 내가 여기 가졌다

.action-link { 
    -fx-skin: "ActionLinkButtonSkin"; 
} 

답변

0

문제는 내가 컨트롤에 action-link 스타일을 추가하지 않은 것입니다. 다음은 간단한 ActionLink 컨트롤의 전체 버전입니다.

public class ActionLink extends Control { 
    static { 
     // Stylesheets is a custom class that resides alongside my CSS files 
     // and returns properly externalized locations in a convention based 
     // manner. 
     StyleManager.getInstance().addUserAgentStylesheet(
      Stylesheets.byConvention(ActionLink.class) 
     ); 
    } 

    private final StringProperty text = new SimpleStringProperty(); 
    public final StringProperty textProperty() {return text;} 
    public final String getText() {return text.get();} 
    public final void setText(String text) {this.text.set(text);} 

    public ActionLink() { 
     getStyleClass().setAll("action-link"); 
    } 
} 
관련 문제