首页 > 编程语言 > 详细

冯斌:JavaFx实例(九)“Text”

时间:2014-11-08 02:13:18      阅读:343      评论:0      收藏:0      [点我收藏+]

    在JavaFxText类定义了一个node这个node能显示字符串,如下图所示。


 bubuko.com,布布扣

    其中点(x,y)是字符串的起点。Text对象通常放在一个pane对象里。Pane对象的左上角坐标是(0,0),右下角的坐标是(pane.getWidth()pane.getHeight())。多行字符串用\n分割开来。

   

   Text类的UML图如下图所示。一个shape就是一个nodeShape类是其他所有图形类的根类。

bubuko.com,布布扣

程序实例清单如下:

 

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

  }

}

 

 

运行结果如下:

bubuko.com,布布扣


冯斌:JavaFx实例(九)“Text”

原文:http://fengbin8606.blog.51cto.com/8840305/1574252

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!