javafx Create a Button


Example

Creation of a Button is simple:

Button sampleButton = new Button();

This will create a new Button without any text or graphic inside.

If you want to create a Button with a text, simply use the constructor that takes a String as parameter (which sets the textProperty of the Button):

Button sampleButton = new Button("Click Me!");

If you want to create a Button with a graphic inside or any other Node, use this constructor:

Button sampleButton = new Button("I have an icon", new ImageView(new Image("icon.png")));