JavaFX TextArea 換行文字

Sheeraz Gul 2022年7月18日
JavaFX TextArea 換行文字

文字區域用於輸入大文字。本教程演示瞭如何使用 JavaFX 在 TextArea 中換行。

JavaFX TextArea 換行文字


setWrapText(true) 方法將文字包裝在 TextArea 或任何其他元素中。按照分步過程將文字換行在文字區域中。

  • 建立一個擴充套件 Application 的類。
  • 用內容建立一個 TextArea
  • 將文字區域的方法 setWrapText() 設定為 true
  • 設定 TextArea 的大小。
  • 建立場景並將其顯示在舞臺上。
  • 最終輸出將是包裹在 TextArea 中的文字。


package delftstack;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class TextArea_Wrap extends Application {
    public void start(Stage TextArea_Stage) {
        String Content = "DelftStack is a resource for everyone interested in programming, "
        		+ "embedded software, and electronics. It covers the programming languages "
        		+ "like Python, C/C++, C#, and so on in this website's first development stage. "
        		+ "Open-source hardware also falls in the website's scope, like Arduino, "
        		+ "Raspberry Pi, and BeagleBone. DelftStack aims to provide tutorials, "
        		+ "how-to's, and cheat sheets to different levels of developers and hobbyists..";
        //Create a Label
        TextArea Text_Area = new TextArea(Content);
        //wrap the textArea
        //Set the maximum width of the textArea
        //Set the position of the textArea
        Group TextArea_Root = new Group();
        //Set the stage
        Scene TextArea_Scene = new Scene(TextArea_Root, 595, 150, Color.BEIGE);
        TextArea_Stage.setTitle("Label Example");
    public static void main(String args[]){


TextArea 換行文字

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

相關文章 - JavaFX Text