Mam GridPane
wypełniony 1-literową etykietą.JavaFx GridPane - jak wyśrodkować elementy
Oto zdjęcie:
image http://s1.directupload.net/images/121010/xu8o79sr.jpg
Oto kod:
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);
Jak mogę wyśrodkować znaki?
Umieściłem je w HBox
i nadałem im odstępy. Próbowałem ustawić textAlignment
etykiety na CENTER
, ale to oczywiście nie działa.
Próbowałem to również:
gp.setAlignment(Pos.CENTER);
czy ktoś pomysł? Dzięki!