I have a very difficult temporary positioning of text in HBox. I can set the horizontal alignment of the text, but I can not set the vertical alignment of the text. I am trying to set the text in the vertical center of the Hbox, but it appears at the top.
Any help would be greatly appreciated.
// 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);
My code produces the following: http://puu.sh/ccEkp/41a26038a4.png
I like my horizontal positioning. I do not know him in the middle, because I decided that it was so. However, I just care about Vertical Positioning .
I tried the following separately:
checkForUpdates.setLayoutY(20); checkForUpdates.setY(20);
I chose number 20 because I wanted to move the text 20 pixels down from the top of the HBox. I calculated this value in Photoshop. Although if there is a better way to set the text to the vertical center of the HBox, please enlighten me.
Thanks again for your help!
java javafx javafx-8
Sameer
source share