我不知道为什么单元格内容会超过网格窗格行约束的限制,尽管设置了最大值。我试图以某种方式剪辑它,但我没有得到单元格的实际高度(当我动态更改它时)。正如您在图像上看到的,绿色矩形太大了。我怎样才能动态限制它的高度?
这是一个小例子:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
GridPane gp = new GridPane();
gp.setGridLinesVisible(true);
gp.setVgap(10);
gp.add(new Pane(new Rectangle(100,100,Color.rgb(255, 0, 0, 0.5))), 0, 0);
gp.add(new Pane(new Rectangle(100,200,Color.rgb(0,255,0,0.5))), 0, 1);
gp.getRowConstraints().add(new RowConstraints(50,100,110));
gp.getRowConstraints().add(new RowConstraints(50,100,110));
Scene scene = new Scene(gp,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}