Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically centering a label in a HBox control with Javafx

I'm using a HBox as a container for a label and a textbox. I'd like for both of them to be vertically centered, but no matter how try that doesn't seem to end up happening:

enter image description here

Here's my current code:

  setScene(new Scene(new HBox(10) {
    setPadding(new Insets(10, 10, 10, 10))

    getChildren.add(new Label("Text to find:") { setAlignment(Pos.CENTER) })
    getChildren.add(new TextField() { setMinWidth(300) })
  }))

Thanks

like image 618
devoured elysium Avatar asked Dec 19 '22 17:12

devoured elysium


1 Answers

Call setAlignment(Pos.CENTER) on the HBox.

like image 124
James_D Avatar answered Mar 06 '23 22:03

James_D