This example demonstrates using JavaFx To change the font of text, creating shadows and Reflections of text. The following three classes will be used:
Javafx.scene.text.Font
Javafx.scene.effect.DropShadow
Javafx.scene.effect.Reflection
The code for this example is as follows:
import javafx.application.application;import javafx.scene.layout.pane; import javafx.scene.scene; import javafx.scene.effect.dropshadow; import javafx.scene.effect.reflection; import javafx.scene.paint.color; import Javafx.scene.text.font; import javafx.scene.text.text; import javafx.stage.stage;public class FontEffect extends Application { @Override // Override the start method in the application class public void start (stage primarystage) { Pane pane = new Pane (); scene scene = new scene (pane, 550, 250, Color.White); // serif with drop shadow text text2 = new text (50, 50, "javafx programing , fengbin "), font serif = font.font (" serif ", 30); Text2.setfont (serif); text2.setfill (color.red); dropshadow dropshadow = new dropshadow (); dropshadow.setoffsetx (2.0f); Dropshadow.setoffsety (2.0f); dropshadow.setcolor (Color.rgb (50, 50, 50, .588)); text2.seteffect (DropShadow); pane.getchildren (). Add (Text2); // sanserif text text3 = new text (50, 100, " javafx programing fengbin "); font sanserif = font.font (" SanSerif ", text3.setfont (Sanserif); text3.setfill (Color.Blue); Pane.getchildren (). Add (Text3); //monospaced text text4 = new text (50, 150, "Javafx&nbsP programing fengbin "); font monofont = font.font (" Monospaced ", 30); text4.setfont (Monofont); text4.setfill (Color.BLACK); pane.getchildren (). Add (TEXT4); reflection refl = new reflection (); refl.setfraction (0.8f); text4.seteffect (REFL ); primarystage.settitle ("FontEffect");// set the stage title primarystage.setscene (Scene); // place the scene in the Stage primarystage.show ();// display the stage }}
The results of the operation are as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/4E/A0/wKiom1RgzGqxup9cAAEK6HdnSIk908.jpg "title=" Qq20141110223014.png "alt=" Wkiom1rgzgqxup9caaek6hdnsik908.jpg "/>
Description
1. the 0.588 in line code represents transparency.
2. the 0.8f in the first line of code indicates that you can see The reflection of the 80%.
This article is from the "Fengbin Technology blog" blog, make sure to keep this source http://fengbin8606.blog.51cto.com/8840305/1575165
Fengbin: JavaFX instance (13) "FontEffect"