FontPositure类是JavaFX的一部分。FontPosition类指定字体是常规字体还是斜体字体。FontPositure类继承 枚举类 .
null
常用方法:
方法 | 解释 |
---|---|
findByName(字符串n) | 返回其名称。 |
valueOf(字符串n) | 返回具有指定名称的字体。 |
价值观() | 返回一个包含该类型所有元素的数组。 |
用于创建字体对象、设置指定姿势并将其应用于文本的Java程序: 在这个程序中,我们将创建两个文本对象,并将其中一个的字体姿态设置为 有规律的 另一个是 斜体 。然后将文本设置为文本流,并将此文本流添加到VBox,然后添加 vbox 添加到场景,并将场景添加到舞台。另外,设置textflow的行距和文本对齐方式以及vbox的间距。打电话给 show() 函数来显示最终结果。
// Java Program to create a font object and set // a specified posture and apply it to a text import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.layout.*; import javafx.scene.paint.*; import javafx.scene.text.*; import javafx.geometry.*; import javafx.scene.layout.*; import javafx.scene.shape.*; public class FontPosture_1 extends Application { // launch the application public void start(Stage stage) { try { // set title for the stage stage.setTitle( "FontPosture" ); // create TextFlow TextFlow text_flow = new TextFlow(); // create text Text text_1 = new Text( "GeeksforGeeks" ); // set the text color text_1.setFill(Color.GREEN); // create a font Font font = Font.font( "Verdana" , FontWeight.EXTRA_BOLD, FontPosture.REGULAR, 25 ); // set font of the text text_1.setFont(font); // create text Text text_2 = new Text( "A Computer Science portal for geeks" ); // set the text color text_2.setFill(Color.GREEN); // create a font Font font1 = Font.font( "Verdana" , FontWeight.EXTRA_BOLD, FontPosture.ITALIC, 12 ); // set font of the text text_2.setFont(font1); // set text text_flow.getChildren().add(text_1); text_flow.getChildren().add(text_2); // set line spacing text_flow.setLineSpacing( 20 .0f); // set text alignment text_flow.setTextAlignment(TextAlignment.CENTER); // create VBox VBox vbox = new VBox(text_flow); // set alignment of vbox vbox.setAlignment(Pos.CENTER); // create a scene Scene scene = new Scene(vbox, 400 , 300 ); // set the scene stage.setScene(scene); stage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // launch the application launch(args); } } |
输出:
注: 以上程序可能无法在联机IDE中运行,请使用脱机编译器。
参考: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/text/FontPosture.html
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END