Source of ShowText.java


  1: 
  2: import javafx.application.Application;
  3: import javafx.scene.Scene;
  4: import javafx.scene.layout.Pane;
  5: import javafx.scene.paint.Color;
  6: import javafx.geometry.Insets;
  7: import javafx.stage.Stage;
  8: import javafx.scene.text.Text;
  9: import javafx.scene.text.Font;
 10: import javafx.scene.text.FontWeight;
 11: import javafx.scene.text.FontPosture;
 12: 
 13: public class ShowText extends Application {
 14:   @Override // Override the start method in the Application class
 15:   public void start(Stage primaryStage) {
 16:     // Create a pane to hold the texts
 17:     Pane pane = new Pane();
 18:     pane.setPadding(new Insets(5, 5, 5, 5));
 19:     Text text1 = new Text(20, 20, "Programming is fun");
 20:     text1.setFont(Font.font("Courier", FontWeight.BOLD,
 21:       FontPosture.ITALIC, 15));
 22:     pane.getChildren().add(text1);
 23: 
 24:     Text text2 = new Text(60, 60, "Programming is fun\nDisplay text");
 25:     pane.getChildren().add(text2);
 26: 
 27:     Text text3 = new Text(10, 100, "Programming is fun\nDisplay text");
 28:     text3.setFill(Color.RED);
 29:     text3.setUnderline(true);
 30:     text3.setStrikethrough(true);
 31:     pane.getChildren().add(text3);
 32: 
 33:     // Create a scene and place it in the stage
 34:     Scene scene = new Scene(pane);
 35:     primaryStage.setTitle("ShowText"); // Set the stage title
 36:     primaryStage.setScene(scene); // Place the scene in the stage
 37:     primaryStage.show(); // Display the stage
 38:   }
 39: 
 40:   /**
 41:    * The main method is only needed for the IDE with limited
 42:    * JavaFX support. Not needed for running from the command line.
 43:    */
 44:   public static void main(String[] args) {
 45:     launch(args);
 46:   }
 47: }