
import javafx.application.Application; 
import javafx.scene.Node; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.ButtonBar; 
import javafx.scene.control.Label; 
import javafx.scene.control.Tooltip; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.layout.Region; 
import javafx.stage.Stage; 

public class JavaFXTestApplication extends Application { 
    public JavaFXTestApplication() { 
    } 

    @Override public void start(Stage primaryStage) throws Exception { 

        Scene scene = new Scene(getContentPane()); 

        primaryStage.setTitle("ButtonBar Test Program"); 
        primaryStage.setScene(scene); 
        primaryStage.sizeToScene(); 
        primaryStage.setOnCloseRequest((e) -> System.exit(0)); 
        for (int n = 9; n < 11; n++) { 
            Stage stage = new Stage(); 
            stage.setScene(new Scene(getContentPane1(n, stage))); 
            stage.sizeToScene(); 
            stage.show(); 
        } 
        primaryStage.show(); 
    } 

    private BorderPane getContentPane() { 
        return new BorderPane(new Label("ButtonBar has an issue")); 
    } 

    public Parent getContentPane1(int n, Stage stage) { 
        // ButtonBar buttonBar = new ButtonBar() { 
        // @Override protected double computePrefWidth(double height) { 
        // resizeButtons(); 
        // double w = super.computePrefWidth(height); 
        // System.out.println("computePrefWidth(" + w + ")"); 
        // return w; 
        // } 
        // 
        // private void resizeButtons() { 
        // final List<? extends Node> buttons =getButtons(); 
        // 
        // // determine the widest button 
        // double widest = -1; 
        // for (Node button : buttons) { 
        // if (ButtonBar.isButtonUniformSize(button)) { 
        // widest = Math.max(button.prefWidth(-1), widest); 
        // } 
        // } 
        // 
        // // set the width of all buttons 
        // for (Node button : buttons) { 
        // if (ButtonBar.isButtonUniformSize(button)) { 
        // sizeButton(button, widest); 
        // } 
        // } 
        // } 
        // 
        // private void sizeButton(Node btn, double pref) { 
        // if (btn instanceof Region) { 
        // Region regionBtn = (Region) btn; 
        // 
        // regionBtn.setPrefWidth(pref); 
        // } 
        // } 
        // 
        // }; 
        // 
        ButtonBar buttonBar = new ButtonBar(); 
        buttonBar.setButtonMinWidth(Region.USE_PREF_SIZE); 

        for (int i = n; i >= 1; i--) { 
            buttonBar.getButtons().add(createButton("ok", "OK", true, "" + i)); 
        } 

        return buttonBar; 
    } 

    private Node createButton(String name, String toolTip, boolean enabled, String buttonText) { 
        Button button = new Button(); 
        button.setId(name + "Button"); 
        button.setTooltip(new Tooltip(toolTip)); 
        if (buttonText != null) { 
            button.setText(buttonText); 
        } 
        button.setDisable(!enabled); 
        button.setMinWidth(Region.USE_PREF_SIZE); 
        return button; 
    } 

    public static void main(String[] args) { 
        launch(args); 
    } 
} 
