Answer the question
In order to leave comments, you need to log in
Java FX how to center an element?
There is a code
package sample;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.stage.Stage;
public class Main extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage window)
{
Group root = new Group();
Scene scene = new Scene(root, 800,800);
ProgressBar prbar = new ProgressBar();
prbar.setMinSize(250,50);
root.getChildren().add(prbar);
window.setScene(scene);
window.setResizable(false);
window.setTitle("Title");
window.show();
}
}
Answer the question
In order to leave comments, you need to log in
I would just change the Group to any other container that has a .setAlignment() method
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage window)
{
VBox root = new VBox(); //◄
Scene scene = new Scene(root, 800,800);
ProgressBar prbar = new ProgressBar();
prbar.setMinSize(250,50);
root.setAlignment(Pos.CENTER); //◄
root.getChildren().add(prbar);
window.setScene(scene);
window.setResizable(false);
window.setTitle("Title");
window.show();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question