定義されたサイズのボックス全体に均等に3行ずつ配信するために9桁の数字を取得しようとしています。JavaFXパネル全体で均等に9桁の数字を配布しレイアウトする方法
これまでのところ、私は途中で凝集しから番号を防止することが見出された唯一の一貫性のある方法は、追加することです中央の桁に2つの余分なスペース、それぞれの側に1つ余分なスペース文字(例: "2"、 "5"、 "8")。確かに、これらの数字をこれよりもレイアウトする方がいいですか?
パブリッククラスDemoCodeは、あなたがあなたのレイアウトにTilePaneまたはGridPaneを使用することができ、アプリケーション{
// Private Class
class PossibleCellValue extends Text {
PossibleCellValue(String value) {
super(value);
setFont(FONT_FOR_POSSIBLE_VALUES);
}
}
// Private Class
class Cell extends VBox {
Cell() {
super();
this.setBorder(borderBlack);
this.setPrefSize(CELL_SIZE, CELL_SIZE);
PossibleCellValue guess1 = new PossibleCellValue("1");
PossibleCellValue guess2 = new PossibleCellValue(" 2 ");
PossibleCellValue guess3 = new PossibleCellValue("3");
PossibleCellValue guess4 = new PossibleCellValue("4");
PossibleCellValue guess5 = new PossibleCellValue(" 5 ");
PossibleCellValue guess6 = new PossibleCellValue("6");
PossibleCellValue guess7 = new PossibleCellValue("7");
PossibleCellValue guess8 = new PossibleCellValue(" 8 ");
PossibleCellValue guess9 = new PossibleCellValue("9");
HBox box1 = new HBox(guess1, guess2, guess3);
HBox box2 = new HBox(guess4, guess5, guess6);
HBox box3 = new HBox(guess7, guess8, guess9);
VBox vbox = new VBox(box1, box2, box3);
getChildren().add(vbox);
this.setAlignment(Pos.CENTER);
}
}
// Normal start method
public void start(Stage stage) throws Exception {
Scene scene = new Scene(new Cell());
stage.setScene(scene);
stage.setTitle("Demo Code");
stage.show();
} // DemoCode
public static void main(String[] args) {
Application.launch(args);
}
static protected final BorderStroke strokeBlack = new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderStroke.THIN);
public static final Border borderBlack = new Border(strokeBlack);
private static final int FONT_SIZE_FOR_POSSIBLE_VALUES = 15;
private static final Font FONT_FOR_POSSIBLE_VALUES = Font.font("Courier", FontWeight.NORMAL, FONT_SIZE_FOR_POSSIBLE_VALUES);
static protected final int CELL_SIZE = 54;
} // DemoCode.java
質問は、Oracleのフォーラムにクロスポストだったし、そこに答えた:[パネル全体に均一に9桁の数字を配布し、レイアウト](HTTPS: //community.oracle.com/thread/3996086) – jewelsea