Add labels and a button to an HBox with alignment set to BASELINE_LEFT.
Make the preferred size of the Button larger than normal.
Text is not aligned to the baseline.
See the following test case:
package hboxalignment;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class HBoxAlignment extends Application {
@Override
public void start(Stage primaryStage) {
Button tallButton = new Button("Tall button");
tallButton.setPrefHeight(32);
HBox hbox = new HBox(
new Label("Label1"),
new Label("Label2"),
tallButton
);
hbox.setAlignment(Pos.BASELINE_LEFT);
VBox vbox = new VBox(hbox);
Scene scene = new Scene(vbox, 500, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Make the preferred size of the Button larger than normal.
Text is not aligned to the baseline.
See the following test case:
package hboxalignment;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class HBoxAlignment extends Application {
@Override
public void start(Stage primaryStage) {
Button tallButton = new Button("Tall button");
tallButton.setPrefHeight(32);
HBox hbox = new HBox(
new Label("Label1"),
new Label("Label2"),
tallButton
);
hbox.setAlignment(Pos.BASELINE_LEFT);
VBox vbox = new VBox(hbox);
Scene scene = new Scene(vbox, 500, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
- duplicates
-
JDK-8176134 Baseline calculation for labeled nodes does not work when graphics are set
- Closed
- relates to
-
JDK-8276671 Iterative layout algorithm
- Open