JavaFX HBox Alignment

前端 未结 2 2133
隐瞒了意图╮
隐瞒了意图╮ 2021-02-18 19:09

I\'ve been working on a software using JavaFX and I have a stupid but worrying problem.

In certain part of the code I have a HBox, and, inside of it three

2条回答
  •  猫巷女王i
    2021-02-18 19:32

    This is a most common alignment issue when you want to place an item towards the two corners of the Layout.

    Let us say you want to have :

    HBox
      |
      ImageView (Left)
      Label (Center)
      VBox (Right)
    

    I very simple solution is to use two extra Regions. One in between ImageView & Label. The other in between Label and VBox.

    HBox
      |
      ImageView (Left)
      Region
      Label (Center)
      Region
      VBox (Right)
    

    These Regions must have HGrow set as Priority.Always, so that if you resize the HBox, these two will grow, keeping the other elements intact in their location.

    FXML example :

    
    
    
    
    
    
    
    
       
          
             
                
             
          
          
          
    
    

    Please note the HBox.hgrow="ALWAYS" in both the Regions.

    Output

    enter image description here

提交回复
热议问题