-2

Can anyone tell me how to move the border of a button away from the button? In other words giving it some kind of outsets or giving some padding to the button from its border or stroke.

Radiodef
  • 37,180
  • 14
  • 90
  • 125
Learner
  • 1
  • 2
  • Have you tried solving this on your own? There is a `padding` property that does exactly what you want to achieve. (`Button` doesn't really use border strokes, but overlayed background fills btw...) – fabian Jun 22 '18 at 01:14
  • Please add your code where you are facing the problem. – habib Jun 22 '18 at 04:01
  • First of all Thank you for your Response . And Yes I tried it with the padding property but it moves the button with itself But my aim is to move the border away from the Button. Consider it like the border is enclosing the Button a bit far from the Button Like a Rectangle enclosing another rectangle but with a distance of 5px to 10px for example. – Learner Jun 22 '18 at 04:49

1 Answers1

1

It is fairly simple to increase the padding of a button; just use the setPadding() method and pass new Insets().

Here's an MCVE to show it in action:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        VBox root = new VBox();
        root.setPadding(new Insets(10));
        root.setAlignment(Pos.CENTER);

        Button button = new Button("Big Borders!");
        button.setPadding(new Insets(20));

        root.getChildren().add(button);

        primaryStage.setWidth(200);
        primaryStage.setHeight(200);
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }
}
Zephyr
  • 9,885
  • 4
  • 28
  • 63
  • Thank you for your Cooperation Sir, I tried the same thing But it moves the Button from the wall of the stage But I want the Border (which I have assigned the Button by Including the Border Class) to move away from the Button itself but in a proportional manner like a big rectangle surrounding another Rectangle – Learner Jun 22 '18 at 04:55
  • I'm sorry, but I have no idea what anything that you just said means. Maybe you should provide some of your code along with a clear explanation of what you expect to happen. – Zephyr Jun 22 '18 at 05:02