HOWTO · JavaFX
JavaFX에서 TextArea 텍스트 줄 바꿈
이 자습서에서는 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
Text_Area.setWrapText(true);
// Set the maximum width of the textArea
Text_Area.setMaxWidth(300);
// Set the position of the textArea
Text_Area.setTranslateX(30);
Text_Area.setTranslateY(30);
Group TextArea_Root = new Group();
TextArea_Root.getChildren().add(Text_Area);
// Set the stage
Scene TextArea_Scene = new Scene(TextArea_Root, 595, 150, Color.BEIGE);
TextArea_Stage.setTitle("Label Example");
TextArea_Stage.setScene(TextArea_Scene);
TextArea_Stage.show();
}
public static void main(String args[]) {
launch(args);
}
}
위의 코드는 텍스트가 래핑된 텍스트 영역을 생성합니다. 출력 참조: