我正在使用名为 mainBut.css
的外部 css 文件来对齐 JavaFX 按钮的文本,
按钮代码:
<Button fx:id="hostelBut"
layoutX="7.0"
layoutY="100.0"
onAction="#hostelAction"
prefHeight="30.0"
prefWidth="150.0"
styleClass="mainBut"
stylesheets="@../resources/css/mainBut.css"
text="Hostel">
mainBut.css
文件
.mainBut {
-fx-background-color: #fdfdfd;
-fx-alignment: LEFT;
-fx-border-color: #bdc3c7;
}
当我编译此文件并通过 NetBeans 运行它时,我收到以下警告。
WARNING: Caught java.lang.IllegalArgumentException: No enum constant javafx.geometry.Pos.LEFT' while calculating value for '-fx-alignment' from rule '*.mainBut' in stylesheet jar:file...
我该怎么做才能修复此警告?
最佳答案
LEFT
不是 -fx-alignment
的有效值属性(property)。有效值为:
[ top-left | top-center | top-right | center-left | center | center-right bottom-left | bottom-center | bottom-right | baseline-left | baseline-center | baseline-right ]
这些值被映射到它们在 Pos
中对应的枚举类。
您可能需要 center-left
来代替,它表示垂直定位在中心,水平定位在左侧。
关于java - 对 -fx-alignment : LEFT saying no enum constant javafx. geometry.Pos.LEFT 发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33475452/