Reputation:
Is it possible to override a JavaFX CSS definition in code?
For example, in my CSS file I defined a button's height as follows:
.button {
-fx-pref-height: 30px;
}
When I try to override this height for some button in code...
Button button = new Button();
button.setPrefSize(100, 50); // width, height
...the button still has a height of 30 pixels.
Upvotes: 1
Views: 2338
Reputation: 11154
There are two solutions:
button.setPrefSize(100, 50); // width, height
is called after the Button
became visible.button.prefHeightProperty().bind(new SimpleDoubleProperty(60));
Upvotes: 3