所以我的老师刚刚开始教我们如何使用JavaFx,直到现在,我以为我对这些材料有很好的把握。但是,我陷入困境,我不知道如何解决问题,甚至是导致问题的原因。我正在尝试创建一个绿色矩形,它是64x64网格上的三个节点高。网格显示得很好但是对于我的生活,我无法理解为什么矩形也没有显示出来。有人可以帮我弄清楚矩形不会出现的原因吗?我确信这是一个小小的愚蠢问题,但我再也看不到了。这是我的代码:
public class test2 extends Application {
private Cell[][] cell = new Cell[64][64];
public void start(Stage primaryStage) {
GridPane pane = new GridPane();
pane.setStyle("-fx-background-color: black");
for (int col = 1; col < 64; col++)
for (int row = 1; row < 64; row++)
pane.add(cell[col][row] = new Cell(), row, col);
Rectangle rectangle = new Rectangle(1,3);
rectangle.setFill(Color.GREEN);
VBox box2 = new VBox(rectangle);
box2.setAlignment(Pos.CENTER);
BorderPane bp = new BorderPane();
bp.setCenter(pane);
Scene scene = new Scene(bp, 1000, 700);
primaryStage.setScene(scene);
primaryStage.show();
}
public class Cell extends Pane{
public Cell(){
setStyle("-fx-border-color: white");
setPrefSize(1000, 1000);
return;
}
}
public static void main(String[] args) {
launch(args);
}