How to set height and width of the Label
with respect to GridPane
row height and column width?
Please check my below images
this image is minimized screen
this image is my label layout properties
I want to resize the Label
with respect to GridPane
row height and column width.
Through code I am setting the background color for the label like below.
if(cmnd1.WIM.equals("Y")){
javafx.application.Platform.runLater( new Runnable() {
@Override
public void run() {
lsduController1.oneWIM.setGraphic(new ImageView(new Image("/images/Wim_T.png")));
lsduController1.oneWIM.setStyle("-fx-background-color: none;");
}
});
} else {
javafx.application.Platform.runLater( new Runnable() {
@Override
public void run() {
lsduController1.oneWIM.setGraphic(new ImageView(new Image("/images/Wim_F.png")));
lsduController1.oneWIM.setStyle("-fx-background-color: Red;");
}
});
}
The issue here is setting the maxHeight
and maxSize
to USE_COMPUTED_SIZE
.
Use MAX_VALUE
instead
<Label style="-fx-background-color: red;" text="Label">
<maxHeight>
<Double fx:constant="MAX_VALUE"/>
</maxHeight>
<maxWidth>
<Double fx:constant="MAX_VALUE"/>
</maxWidth>
</Label>
(This should be available from the dropdown in SceneBuilder too.)
To resize the ImageView
too, bind the fitWidth
and fitHeight
properties to the label size. Eg:
ImageView imageView = new ImageView(new Image("/images/Wim_F.png"));
imageView.setPreserveRatio(true);
imageView.fitWidthProperty().bind(lsduController1.oneWIM.widthProperty().subtract(10d));
imageView.fitHeightProperty().bind(lsduController1.oneWIM.heightProperty().subtract(10d));
lsduController1.oneWIM.setGraphic(imageView);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.