【问题标题】:Is it possible to control the values of non-color fields by looked-up?是否可以通过查找来控制非颜色字段的值?
【发布时间】:2017-10-13 15:19:07
【问题描述】:

CSS

主类切换开关

.toggle-switch {
    radius: 16;

    thumb-area-background-color: rgba(255, 255, 255, 1);
    thumb-area-border-width: 2;
    thumb-area-border-color: #d9d9d9;
}

还有子类thumb-area

.thumb-area {
    -fx-background-radius: radius;
    -fx-border-radius: radius;

    -fx-background-color: thumb-area-background-color;
    -fx-border-width: thumb-area-border-width;
    -fx-border-color: thumb-area-border-color;   
}

字段thumb-area-background-color и thumb-area-border-color,负责颜色,从代码中完美变化,处理无误:

toggleSwitch.setStyle("thumb-background-color: " + getRGBAString(color));
toggleSwitch.setStyle("thumb-area-background-color: " + getRGBAString(color));

但是字段radius и thumb-area-border-width,没有被处理!当我启动程序时,控制台显示:

WARNING: Caught 'java.lang.ClassCastException: java.lang.Double cannot be cast to com.sun.javafx.css.Size' while converting value for '-fx-background-radius' from rule '*.thumb-area' in stylesheet file:/...
*date* javafx.scene.CssStyleHelper calculateValue

WARNING: Caught 'java.lang.ClassCastException: java.lang.Double cannot be cast to com.sun.javafx.css.Size' while converting value for '-fx-border-radius' from rule '*.thumb-area' in stylesheet file:/...
*date* javafx.scene.CssStyleHelper calculateValue

WARNING: Caught 'java.lang.ClassCastException: java.lang.Double cannot be cast to com.sun.javafx.css.Size' while converting value for '-fx-border-width' from rule '*.thumb-area' in stylesheet file:/...
*date* javafx.scene.CssStyleHelper calculateValue

文件的路径和日期被删除。

是否可以通过looked-up控制非颜色字段的值,或者如果没有这样的选项,如何更好地从代码中以编程方式更改这些值而不覆盖 css 字段(例如 setStyle 用于 thumbArea 所有值来自 cssthumb-area 迷路了)

使用 setStyle 以编程方式生成所有字段的方法不适合。

【问题讨论】:

  • 如果您将radius: 16 更改为radius: 16 16 16 16,您会得到相同的错误还是不同的错误?
  • 这无济于事 + 在我的示例中,我写道尝试设置宽度时也会发生错误。

标签: java css javafx


【解决方案1】:

看起来radius 被存储为 Double 而不是 Size,这是 -fx-background-radius 所期望的。 试试radius: 16px;,看看效果好不好?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    相关资源
    最近更新 更多