11

1文字のラベルがGridPaneいっぱいです。

ここに画像があります:

画像

コードは次のとおりです。

int charSpacing = 1;
int charsInWidth = 28;
int charsInHeight = 16;

double charWidth = 15;
double charHeight = 20;

GridPane gp = new GridPane();
gp.setAlignment(Pos.CENTER);

Label[] tmp = new Label[charsInHeight*charsInWidth];

String text = "W";
int currArrPos = 0;

for(int y = 0; y < charsInHeight; y++) {
    HBox hbox = new HBox(charSpacing);

    for(int x = 0; x < charsInWidth; x++) {
        tmp[currArrPos] = new Label(text);
        tmp[currArrPos].setTextFill(Paint.valueOf("white"));

        tmp[currArrPos].setMinHeight(charHeight);
        tmp[currArrPos].setMinWidth(charWidth);
        tmp[currArrPos].setMaxHeight(charHeight);
        tmp[currArrPos].setMaxWidth(charWidth);

        tmp[currArrPos].setStyle("-fx-border-color: white;");
        hbox.getChildren().add(tmp[currArrPos++]);

        if(x%2 == 0){
            text = "I";
        } else{
            text = "W";
        }
    }
    gp.add(hbox, 1, y);
}
guiDisplay.getChildren().add(gp);

文字を中央に配置するにはどうすればよいですか?

私はそれらを a に入れ、HBox間隔を空けました。textAlignmentラベルの を にしようとしましたCENTERが、もちろんうまくいきません。

私もこれを試しました:

gp.setAlignment(Pos.CENTER);

誰にもアイデアはありますか?ありがとう!

4

3 に答える 3

28
于 2013-06-19T09:23:54.363 に答える
12

ああ、それは簡単でした。位置合わせを間違えました。これを追加すると、仕事ができます:

tmp[currArrPos].setAlignment(Pos.CENTER);

とにかくありがとう。

于 2012-10-10T09:41:19.920 に答える