Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:55:59+00:00 2026-06-13T17:55:59+00:00

I’m working on a project, and I need to make two buttons absolutly centered

  • 0

I’m working on a project, and I need to make two buttons absolutly centered on the scene.
I haven’t found any built in pane option to do the work, so I had to use alot of binding.
The code for that is really long and I’m quite sure there is an easier way to do the job.
Here is a demo: http://screencast.com/t/pvi5WLko

So what I want to know is, if there’s an easy way to do the same thing and preferably with built in panes or something.

I want the buttons to be centered, no matter how the window is resized. Example:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:56:00+00:00Added an answer on June 13, 2026 at 5:56 pm

    The probably easiest way would be to use a VBox:

    public void start(final Stage stage) throws Exception {
        final Button button0 = new Button("Start learning");
        final Button button1 = new Button("Customize");
    
        final VBox box = new VBox();
        box.setFillWidth(true);
    
        box.getChildren().setAll(button0, button1);
        box.setAlignment(Pos.CENTER);
    
        stage.setScene(new Scene(box));
        stage.setWidth(200);
        stage.setHeight(100);
        stage.show();
    }
    

    Another possible way of doing this is with a GridPane:

    public void start(final Stage stage) throws Exception {
      final Button button0 = new Button("Start learning");
      final Button button1 = new Button("Customize");
    
      final GridPane cPane = new GridPane();
      cPane.getChildren().addAll(button0, button1);
      GridPane.setConstraints(button0, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER);
      GridPane.setConstraints(button1, 0, 1, 1, 1, HPos.CENTER, VPos.CENTER);
    
      final ColumnConstraints columnn0 = new ColumnConstraints();
      columnn0.setPercentWidth(100);
      cPane.getColumnConstraints().addAll(columnn0);
    
      final RowConstraints row0 = new RowConstraints(1);
      row0.setPercentHeight(50);
    
      final RowConstraints row1 = new RowConstraints(1);
      row1.setPercentHeight(50);
    
      cPane.getRowConstraints().addAll(row0, row1);
    
      stage.setScene(new Scene(cPane));
      stage.setWidth(200);
      stage.setHeight(100);
      stage.show();
    }
    

    The idea here would be to configure the rows and columns in the grid to fill your scene using the according constraints objects. The above defines one column and two rows. You can then align your components within the cells of the Grid, using GridPane.setConstraints(…).

    You might want to alter the code slightly to have the top button align to VPos.BOTTOM and the lower one to VPos.TOP, depending on whether you want the buttons to stick together (you’ll then have to define a margin for both, of course).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I need to clean up various Word 'smart' characters in user input, including but
Let's say I'm outputting a post title and in our database, it's Hello Y’all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.