Working in Java FX 2.2. The Scene has a horizontal width that is fixed but is unknown at compile time. I want to place 2 or more buttons in a horizontal row that completely fills the horizontal space in the Scene AND that are each exactly the same width. The number of buttons changes dynamically with the program state. What program snippet will accomplish this?
Share
This code from the HBox javadoc will almost do what you want, except that “buttons themselves are different sizes based on the text contained in the button – wider text causes wider buttons”.
By creating a custom layout pane based on HBox and overriding it’s layout method, you can get exactly the behaviour you describe.
Sample program output:

