2016-08-03 80 views
0

如何设置Label相对于GridPane行高和列宽的高度和宽度?如何使用JavaFX和Scene Builder修复或设置GridPane行高和列宽的标签高度和宽度?

请检查我以下图片

这一形象被最小化屏幕 this one is my minimized screen image

这一个最大化屏幕 This one is my maximized screen image

这个形象是我的标签布局属性
This are my label layout properties

我想要调整Label相对于GridPane行高和列宽。

通过代码我设置标签的背景颜色,如下所示。

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;"); 
     } 
    }); 
} 

回答

0

这里的问题是设置maxHeightmaxSizeUSE_COMPUTED_SIZE

使用MAX_VALUE代替

<Label style="-fx-background-color: red;" text="Label"> 
    <maxHeight> 
     <Double fx:constant="MAX_VALUE"/> 
    </maxHeight> 
    <maxWidth> 
     <Double fx:constant="MAX_VALUE"/> 
    </maxWidth> 
</Label> 

(这应该可以从SceneBuilder下拉了。)

要调整ImageView过,绑定fitWidthfitHeight属性标签尺寸。例如:

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); 
+0

仍然现在我有@fabian – pen1993

+0

同样的问题仍然现在我有同样的问题,我修改像“最大宽度:MAX_VALUE”和‘最大高度:MAX_VALUE’,并在预视图它表示细时我运行应用程序,所以图像将出现在那里,所以有图像的任何影响,请给我sujestion - @fabian – pen1993

+0

给我建议以上评论 - @fabian – pen1993