Stack Ask
Stack Ask

Reputation: 5

set spacing among elements within button javafx

I want to specify spacing between two elements within JavaFX Buttons, Here is the Code :

    ImageView fiv = new ImageView(new Image("/modified/map.png"));
    fiv.setFitHeight(20);
    fiv.setPreserveRatio(true);

    Button cr = new Button( "Crop", fiv);

Here I want to Specify Spacing Between "Crop" and fiv, How can i do this ?

Upvotes: 0

Views: 924

Answers (2)

user1438038
user1438038

Reputation: 6079

As stated already, you can call the setGraphicTextGap() method to adjust the gap:

btnSaveUser.setGraphicTextGap(8.0);

I prefer to define my styles in an external CSS file, however.

If anybody is looking for a FXML equivalent, here it is:

.btnSaveUserClass {
    -fx-graphic-text-gap: 8.0;
}

The style class btnSaveUserClass must be applied to a button in the FXML file:

<Button fx:id="btnSaveUser" mnemonicParsing="true" text="_Save user"
                styleClass="btnSaveUserClass" onAction="#onSaveUserAction"/>

Upvotes: 0

Uluk Biy
Uluk Biy

Reputation: 49215

Use graphicTextGap property of the button.

Upvotes: 5

Related Questions