javafx.scene.text.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 {
// टेक्स्ट फ़ाइल की सामग्री पढ़ना
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");
}
// टेक्स्ट ऑब्जेक्ट बनाना
Text text = new Text(10.0, 25.0, sb.toString());
// टेक्स्ट रैप करना
text.setWrappingWidth(565);
// एलाइनमेंट सेट करना
text.setTextAlignment(TextAlignment.JUSTIFY);
// स्पेस सेट करना
text.setLineSpacing(2.0);
// स्टेज सेट करना
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);
}
}
sample.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 सेट करते हैं तो निम्नलिखित आउटपुट होगा -
