ตั้งแต่ javafx.scene.text.Text คลาสใน JavaFX สืบทอดคลาส Shape ที่สืบทอดสมาชิกทั้งหมด คุณสามารถแก้ไขเส้นขีดและสีของโหนดข้อความได้โดยการตั้งค่าคุณสมบัติเส้นขีด ความกว้างของเส้นขีด และการเติมที่สืบทอดโดยคลาสข้อความ
-
ความกว้างของระยะชัก − คุณสมบัติความกว้างของเส้นขีดระบุ/กำหนดความกว้างของเส้นขอบของรูปร่าง คุณสามารถตั้งค่าความกว้างของขอบเขตโดยใช้ setWidth() เมธอดของคลาส Shape
-
เติม − คุณสมบัติการเติม ระบุ/กำหนดสีที่จะเติมพื้นที่ภายในของรูปร่าง คุณสามารถเติมรูปร่างที่ต้องการด้วยสีที่ต้องการได้โดยใช้ fill() เมธอดของคลาส Shape
-
จังหวะ − คุณสมบัติเส้นขีดระบุ/กำหนดสีของเส้นขอบของรูปร่าง คุณสามารถกำหนดสีของขอบเขตโดยใช้ setStroke() เมธอดของคลาส javafx.scene.shape.Shape
ตัวอย่าง
import java.io.FileNotFoundException;
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.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class SettingStroke_Color extends Application {
public void start(Stage stage) throws FileNotFoundException {
//Creating a text object
String str = "Welcome to Tutorialspoint";
Text text = new Text(30.0, 80.0, str);
//Setting the font
Font font = Font.font("Brush Script MT", FontWeight.BOLD, FontPosture.REGULAR, 65);
text.setFont(font);
//Setting the color of the text
text.setFill(Color.BROWN);
//Setting the width
text.setStrokeWidth(2);
//Setting the stroke color
text.setStroke(Color.BLUE);
//Setting the stage
Group root = new Group(text);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Stroke And Color");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
} ผลลัพธ์
