কম্পিউটার টিউটোরিয়াল

জাভাFX-এ টেক্সট অ্যালাইনমেন্ট এডজাস্ট করা

র‍্যাপিং উইডথ এবং টেক্সট অ্যালাইনমেন্ট

টেক্সটের জন্য একটি ফিক্সড প্রস্থ সেট করতে wrappingWidth প্রপার্টি ব্যবহার করা হয়। এটি না দেওয়া থাকলে সবচেয়ে লম্বা লাইনের দৈর্ঘ্য বাউন্ডিং বক্সের প্রস্থ মনে করা হয়।

টেক্সট অ্যালাইনমেন্ট হলো বাউন্ডিং বক্সের মধ্যে টেক্সটের আড়াআড়ি সাজানোর পদ্ধতি। setTextAlignment() মেথড দিয়ে এটি কন্ট্রোল করা যায়। এটি TextAlignment এনামের কনস্ট্যান্টগুলো গ্রহণ করে:

  • CENTER - টেক্সট বাউন্ডিং বক্সের মাঝখানে অ্যালাইন করে।
  • JUSTIFY - টেক্সট বাউন্ডিং বক্সের মধ্যে জাস্টিফাই করে।
  • LEFT - টেক্সট বামপাশে অ্যালাইন করে।
  • RIGHT - টেক্সট ডানপাশে অ্যালাইন করে।

উদাহরণ

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 TextAllignment extends Application { 
    public void start(Stage stage) throws FileNotFoundException { 
        // Reading the contents of a text file. 
        InputStream inputStream = new FileInputStream("D:\\sample.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.RIGHT); 
        // Setting the stage 
        Group root = new Group(text); 
        Scene scene = new Scene(root, 595, 150, Color.BEIGE); 
        stage.setTitle("Text Alignment"); 
        stage.setScene(scene); 
        stage.show(); 
    } 
    public static void main(String args[]){ 
        launch(args); 
    } 
}

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.

আউটপুট

জাভাFX-এ টেক্সট অ্যালাইনমেন্ট এডজাস্ট করা

অ্যালাইনমেন্ট ভ্যালু পরিবর্তন করলে নিচের আউটপুটগুলো পাওয়া যায়:

LEFT -

জাভাFX-এ টেক্সট অ্যালাইনমেন্ট এডজাস্ট করা

CENTER -

জাভাFX-এ টেক্সট অ্যালাইনমেন্ট এডজাস্ট করা

JUSTIFY -

জাভাFX-এ টেক্সট অ্যালাইনমেন্ট এডজাস্ট করা

  1. ক্রোমে ট্যাবের ভলিউম কীভাবে এডজাস্ট করবেন

  2. Tkinter Text উইজেটে টেক্সট সেন্টার অ্যালাইন কীভাবে করবেন?

  3. টকিন্টার পাইথনে লেবেল টেক্সট পাওয়া

  4. টেক্সটের ক্যাপিটালাইজেশন কীভাবে পরিবর্তন করবেন