2016-04-27 65 views
1

我喜欢在水平布局中放置一个标签和一个按钮(和一个文本字段)。这有效,但基线未对齐。如何解决这个问题?如何在基线对齐标签和按钮?

Baselines are unaligned

预期的结果是,红色线(每个控制的基线)处于相同的高度。

这是FXML:

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.Label?> 
<?import javafx.scene.control.TextField?> 
<?import javafx.scene.layout.HBox?> 

<HBox prefHeight="100.0" prefWidth="400.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <Label text="Label" /> 
     <Button mnemonicParsing="false" text="Button" /> 
     <TextField text="Lorem Ipsum" /> 
    </children> 
</HBox> 

回答

4

添加的对准属性到HBox与值"BASELINE_LEFT"

<HBox alignment="BASELINE_LEFT" prefHeight="100.0" prefWidth="400.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <Label text="Label" /> 
     <Button mnemonicParsing="false" text="Button" /> 
     <TextField text="Lorem Ipsum" /> 
    </children> 
</HBox> 

enter image description here