Let's say that I have an application window and I declare Circle c = new Circle(40,40,40);
, which is initially black. What should I do if I want to fill it with red?
What should I do if I want to fill it with red? (for example, if a button is clicked, then c
becomes red)
You can apply colors to nodes in JavaFX using the setFill() and setStroke() methods. The setFill() method adds color to the surface area of the node whereas the setStroke() method applies color to the boundary of the node. Both methods accept an object of the javafx.
Set a fill on the shape (Java 8 code):
Circle circle = new Circle(40, 40, 40);
Button button = new Button("Red");
button.setOnAction(e -> circle.setFill(javafx.scene.paint.Color.RED));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With