All JavaFX shapes (Text included, yes letters drawn on screen are considered shapes) can be colored using any one of the millions of colors supported by your device. Color is provided by class javafx.scene.paint.Color which supports several ways to declare an instance of Color. The followings show the different ways the Color class can be created to paint a red circle on the screen: With Color ConstantsThe Color class exposes each colordef w = 400;def h = 200;def circ0 = Circle { centerX: w/2 centerY:h/2 radius: 90 fill:Color.RED}With Color Namedef w = 400;def h = 200;def circ0 = Circle { centerX: w/2 centerY:h/2 radius: 90 fill:Color.web("red")}With RGB Valuesdef w = 400;def h = 200;def circ0 = Circle { centerX: w/2 centerY:h/2 radius: 90 fill:Color.rgb(255,0,0)}With sRGB Valuesdef w = 400;def h = 200;def circ0 = Circle { centerX: w/2 centerY:h/2 radius: 90 fill:Color.color(1.0,0.0,0.0)}With Web Hex Valuesdef w = 400;def h = 200;def circ0 = Circle { centerX: w/2 centerY:h/2 radius: 90 fill:Color.web("#FF0000")}All of previous code snippets will create red circle as shown below: | The materials on this website represent a small sample of content loosely based on the book JavaFX Application Development Cookbook. The book offers far more content with over 80 recipes covering a range of topics from basics to advanced concepts. Buy the BookYou can get your copy of the book directly from the publisher. Click here to order! |

