How to make the Button appear on the right side of a TitledPane JavaFX

I have managed to place a Button inside a TitledPane using setGraphic but I want it to be located on the right side; here is the code:

@Override
public void start(Stage primaryStage) {

    Accordion acordion = new Accordion();

    TitledPane tp1 = new TitledPane();

    Button b1 = new Button();

    b1.setText("X");

    tp1.setGraphic(b1);

    acordion.getPanes().addAll(tp1);

    Scene scene = new Scene(acordion, 300, 250);

    primaryStage.setScene(scene);
    primaryStage.show();
}

public static void main(String[] args) {
    launch(args);
}

The Button should be located on the right but I do not know how to do it

enter image description here

Upvotes: 0

Views: 454

Answers (1)

fabian
fabian

Reputation: 82451

Set the alignment property of TitledPane to CENTER_RIGHT:

tp1.setAlignment(Pos.CENTER_RIGHT);

Upvotes: 1

Related Questions