javafx.scene.text의 줄 간격 속성입니다. 텍스트 클래스는 세로로 텍스트(노드) 줄 사이의 줄 간격을 지정합니다.
setLineSpacing()을 사용하여 이 속성에 값을 설정할 수 있습니다. 방법. 이 메소드는 부울 값을 매개변수로 받아들이고 행 사이에 지정된 공간(세로)을 설정합니다.
예시
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; public class TextSpacing extends Application { public void start(Stage stage) throws FileNotFoundException { //Reading the contents of a text file. InputStream inputStream = new FileInputStream("D:\\sample_text.txt"); Scanner sc = new Scanner(inputStream); StringBuffer sb = new StringBuffer(); while(sc.hasNext()) { sb.append(" "+sc.nextLine()+"\n"); } //Creating a text object Text text = new Text(10.0, 25.0, sb.toString()); //Wrapping the text text.setWrappingWidth(565); //Setting the alignment text.setTextAlignment(TextAlignment.JUSTIFY); //Setting the space text.setLineSpacing(2.0); //Setting the stage Group root = new Group(text); Scene scene = new Scene(root, 595, 150, Color.BEIGE); stage.setTitle("Line Spacing (2.0)"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
샘플.txt
다음은 sample.txt 파일의 내용이라고 가정합니다. -
Tutorials Point originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms. The journey commenced with a single tutorial on HTML in 2006 and elated by the response it generated, we worked our way to adding fresh tutorials to our repository which now proudly flaunts a wealth of tutorials and allied articles on topics ranging from programming languages to web designing to academics and much more.
출력
같은 방식으로 줄간격을 8.0 −