In JavaFx , the Text class defines a node, the node The string can be displayed as shown in.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/4D/F3/wKioL1Rc5wTxJ5h0AAC34yExHro146.jpg "title= "Picture 1.jpg" alt= "wkiol1rc5wtxj5h0aac34yexhro146.jpg"/>
where point (x, y) is the starting point of the string. text objects are usually placed in a pane pane 0,0 pane.getwidth () pane.getheight ()) \n
The UML diagram for the Text class is shown. A shape is a node, andtheshape class is the root class for all other graphics classes.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/F4/wKiom1Rc5rXhmiooAAEN78qYjT4232.jpg "style=" float: none; "title=" image 2.jpg "alt=" Wkiom1rc5rxhmiooaaen78qyjt4232.jpg "/>
The program example list is as follows:
Import javafx.application.Application;
Import Javafx.scene.Scene;
Import Javafx.scene.layout.Pane;
Import Javafx.scene.paint.Color;
Import Javafx.geometry.Insets;
Import Javafx.stage.Stage;
Import Javafx.scene.text.Text;
Import Javafx.scene.text.Font;
Import Javafx.scene.text.FontWeight;
Import Javafx.scene.text.FontPosture;
public class Showtext extends application {
@Override//Override The Start method in the Application class
public void Start (Stage primarystage) {
Create a pane to hold the texts
Pane Pane = new Pane ();
Pane.setpadding (New Insets (5,5,5,5));
Text Text1 = new text (20,20, "programming is fun");
Text1.setfont (Font.font ("Courier", Fontweight.bold,
Fontposture.italic, 15));
Pane.getchildren (). Add (Text1);
Text Text2 = new text (60,60, "programming is Fun\ndisplay Text");
Pane.getchildren (). Add (Text2);
Text Text3 = new text (10,100, "programming is Fun\ndisplay Text");
Text3.setfill (color.red);
Text3.setunderline (TRUE);
Text3.setstrikethrough (TRUE);
Pane.getchildren (). Add (TEXT3);
Create a scene and place it in the stage
Scene scene = new scene (pane);
Primarystage.settitle ("Showtext");//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/M01/4D/F3/wKioL1Rc5xvCAVZqAABcJ3qIMvQ145.jpg "title=" Picture 3.jpg "style=" Float:none; "alt=" wkiol1rc5xvcavzqaabcj3qimvq145.jpg "/>
Fengbin: JavaFX Instance (ix) "Text"