javafx Button Create a Button

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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")));


Got any javafx Question?