How to set size and various attributes for all grids in GridPane in Scenebuilder/JavaFX

时间:2016-04-21 22:09:32

标签: java swing javafx scenebuilder

NOTE: This is not homework. My Swing application was homework, but it's already completed. I'm doing this for my own knowledge to get a better understanding of JavaFX and Scenebuilder.

I created a Swing application that contained a 27x27 grid. Upon clicking "Normal Setup", only the center square is visible.

Swing GUI Initialization

I am attemtping to translate everything into JavaFx, and I am using Scenebuilder. I'm still learning how to use this, and I'm unsure if I have my GridPane placed correctly (Notice how creating a 27 x 27 grid makes it go beyond the bounds of the parent). I can work on that later.

JavaFX GridNode with Scenebuilder

What I would like to know is if you can set all of the attributes for each node across the board. I had to go into my FXML file and manually change each node size in the 27x27 grid. This will get exhausting eventually. Surely there is a way to do this? As you can see each node will have a Label template, and it will only be visible when a certain ant accesses it.

In my Swing version, an example of setting everything for all nodes looks like so:

     setPreferredSize(new Dimension(ColonyView.NODE_SIZE, ColonyView.NODE_SIZE));

where the "NODE_SIZE" is:

    public final static int NODE_SIZE = 96

Any help would be appreciated.

2 个答案:

答案 0 :(得分:1)

Select a node in your GridPane and press STRG + A

答案 1 :(得分:0)

您可以使用CSS设置黄色背景。有关详细信息,请参阅https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html