我正在编写一个JavaFX-8应用程序,想知道是否可以USE_PREF_SIZE通过CSS 设置(例如)Button的最小或最大宽度。该类Region定义USE_PREF_SIZE为Double.NEGATIVE_INFINITY,但是如何在CSS中设置负无穷大?《 JavaFX参考指南》将-fx-min-width, -fx-pref-width, -fx-max-widthas <number>和a <number>定义为以下正则表达式[+|-]? [[0-9]+|[0-9]*"."[0-9]+]
所以也许不可能吗?
我试图(出于娱乐目的)将Java方式分配为负无穷大-1.0/0.0,并且css-parser接受了该值,但是没有预期的效果。有人可以解释为什么它不显示警告或错误吗?
我已经知道如何设定 USE_PREF_SIZE通过代码,而且我也知道如何将min,pref和max设置为相同的值,但是我想以动态方式在css文件中进行设置。
提前致谢
我的InvalidationListener有问题.它在SimpleStringProperty上设置为Listener.但它仅用于SimpleStringProperty的第一次更改.我进入调试模式并在调用SimpleStringProperty :: set的行上创建了一个断点,它开始工作,直到我再次删除了断点.
我做了一个简短的可执行示例程序,它模拟使用计时器修改SimpleStringProperty.您可以在没有断点的情况下运行程序一次,并且在此行有一次断点:property.set(value);
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Main extends Application {
private SimpleStringProperty property;
private int counter;
@Override
public void start(Stage stage) {
// open a window to avoid immediately termination
stage.setWidth(800);
stage.setHeight(600);
BorderPane pane = new BorderPane();
stage.setScene(new Scene(pane));
stage.show();
// create a SimpleObjectProperty
property = new SimpleStringProperty();
property.addListener(observable ->
System.out.println("New value is: " + counter)
);
counter = 0;
// create timer …Run Code Online (Sandbox Code Playgroud)