- Mastering JavaFX 10
- Sergey Grinev
- 145字
- 2021-06-25 21:21:56
Paint
Basic paint is just a color. The Color class is derived from Paint and provides the following options:
- Predefined constants from Color.BLACK to a fancy Color.ANTIQUEWHITE
- Color-building methods and corresponding getters—rgb(), hsb(), web()
- Opacity through a parameter of the aforementioned methods
- Color-adjusting methods—saturate(), darker(), deriveColor(), and others
Here is a small example of semi-transparent color circles to show how colors can blend. I understand it's slightly harder to grasp in the black-and-white picture, so try it on your computer:
// chapter2/paint/ColorsDemo.java
Pane root = new Pane();
root.getChildren().addAll(
// RED, opacity 0.3
new Circle(150,80,70, Color.rgb(255, 0, 0, 0.3)),
// GREEN, opacity 0.3
new Circle(100,180,70, Color.hsb(120, 1.0, 1.0, 0.3)),
// BLUE, opacity 0.3
new Circle(200,180,70, Color.web("0x0000FF", 0.3))
);
The output is as follows:

If you want to get rid of color at all, you can use the special constant Color.TRANSPARENT.