Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX - How can I fill with color a shape?

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)

like image 910
bog Avatar asked Jul 18 '14 14:07

bog


People also ask

How do I change the color of a shape in JavaFX?

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.


1 Answers

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));
like image 61
jewelsea Avatar answered Oct 03 '22 22:10

jewelsea