gpt4 book ai didi

css - 无法在 Gluon 元素上加载皮肤错误

转载 作者:行者123 更新时间:2023-11-28 16:18:20 25 4
gpt4 key购买 nike

我有一个自定义控件 ChoiceTextField,具有相应的 ChoiceTextFieldSkin

protected Skin<?> createDefaultSkin() {
return new ChoiceFieldSkin<T, ChoiceTextField<T>>(this);
}

控件显示正确,但出现以下Exception:

Failed to load skin 'com.gluonhq.impl.charm.a.b.a.ap' for control ChoiceTextField[id=choiceCounter, styleClass=choice-field colored button flat]
java.lang.IllegalArgumentException: argument type mismatch

我可以通过在CSS文件中设置皮肤来解决这个错误:

.choice-field{
-fx-skin: "com.energymeter.control.skin.ChoiceFieldSkin";
}

但我想知道是什么导致了Exception

最佳答案

这段用于创建带有自定义控件的 View 的简短代码片段:

public BasicView(String name) {
super(name);

setCenter(new StackPane(new ChoiceTextField()));
}

class ChoiceTextField<T> extends Control {

public ChoiceTextField() {
getStyleClass().add("button");
}

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

class ChoiceFieldSkin<T> extends SkinBase<ChoiceTextField<T>> {

private final TextField textfield;

public ChoiceFieldSkin(ChoiceTextField<T> control) {
super(control);
textfield = new TextField();

getChildren().add(textfield);
}
}

显示相同的异常:

javafx.scene.control.Control loadSkinClass
Failed to load skin 'com.gluonhq.impl.charm.a.b.a.ap' for control ChoiceTextField@4fb753dd[styleClass=button]
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at javafx.scene.control.Control.loadSkinClass(Control.java:735)

如果您查看 Control.createDefaultSkin() 的 javadoc :

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS {@code -fx-skin} or set explicitly in a sub-class with {@code setSkin(...)}.

(粗体是我的)。

当你设置 getStyleClass().add("button") ,事实证明 Charm 覆盖了 ButtonSkin 以通过 CSS 提供涟漪效果,所以你有你的异常(exception)。

正如您提到的,如果您通过 CSS 显式设置皮肤,则不会发生此异常:

public ChoiceTextField() {

getStyleClass().addAll("choice-field", "button");
getStylesheets().add(getClass().getResource("style.css").toExternalForm());
}


.choice-field {
-fx-skin: '<package name>.ChoiceFieldSkin'
}

关于css - 无法在 Gluon 元素上加载皮肤错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37308488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com