我很难将文本放在HBox中 . 我能够设置文本的水平对齐,但我无法设置文本的垂直对齐 . 我试图在Hbox的垂直中心设置文本,但它出现在顶部 .
任何帮助将非常感激 .
// Create The Updates Progress Bar At The Bottom Of The Window
HBox checkUpdatesBar = new HBox();
checkUpdatesBar.setId("checkUpdatesBar");
checkUpdatesBar.setPrefSize(CHECK_PANE_WIDTH, CHECK_PANE_HEIGHT);
checkUpdatesBar.setMinSize(CHECK_PANE_WIDTH, CHECK_PANE_HEIGHT);
checkUpdatesBar.setMaxSize(CHECK_PANE_WIDTH, CHECK_PANE_HEIGHT);
// Create The 'Check For Updates...' Text
Text checkForUpdates = new Text();
checkForUpdates.setFont(Font.font("Arial Black", FontWeight.BLACK, 15));
checkForUpdates.setWrappingWidth(CHECK_PANE_WIDTH / 2.8);
checkForUpdates.setFill(Color.WHITE);
checkForUpdates.setTextAlignment(TextAlignment.CENTER);
checkForUpdates.setText("Checking For Updates ...".toUpperCase());
checkUpdatesBar.getChildren().add(checkForUpdates);
我喜欢我的水平定位 . 我知道它不在中间,因为我将它设置为那样 . 但是,我只关心 Vertical Positioning .
我分别尝试了以下内容:
checkForUpdates.setLayoutY(20);
checkForUpdates.setY(20);
我选择数字20是因为我想将文本从HBox顶部向下移动20个像素 . 我在Photoshop中计算了这个值 . 虽然如果有更好的方法将文本设置为HBox的垂直中心,请赐教 .
再次感谢您的帮助!