JavaFX Font create

Description

JavaFX Font create

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

public class Main extends Application {
  @Override//from   w  ww  .ja  v  a 2s  . co m
  public void start(Stage primaryStage) {
    // Create a pane to hold the circle
    Pane pane = new StackPane();

    // Create a circle and set its properties
    Circle circle = new Circle();
    circle.setRadius(50);
    circle.setStroke(Color.BLACK);
    circle.setFill(new Color(0.5, 0.5, 0.5, 0.1));
    pane.getChildren().add(circle); // Add circle to the pane

    // Create a label and set its properties
    Label label = new Label("demo2s.com");
    label.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.ITALIC, 20));
    pane.getChildren().add(label);

    Scene scene = new Scene(pane);
    primaryStage.setTitle("FontDemo");
    primaryStage.setScene(scene);
    primaryStage.show();
  }

  public static void main(String[] args) {
    launch(args);
  }
}
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Reflection;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class Main extends Application {

    public static void main(String[] args) {
        Application.launch(args);//from  w ww. j  a  va 2  s.co  m
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Changing Text Fonts");
        Group root = new Group();
        Scene scene = new Scene(root, 330, 250, Color.WHITE);

        // Serif with drop shadow
        Text test2 = new Text(50, 50, "Java 7 Recipes");
        Font serif = Font.font("Serif", 30);
        test2.setFont(serif);
        test2.setFill(Color.RED);
        DropShadow dropShadow = new DropShadow();
        dropShadow.setOffsetX(2.0f);
        dropShadow.setOffsetY(2.0f);
        dropShadow.setColor(Color.rgb(50, 50, 50, .588));
        test2.setEffect(dropShadow);
        root.getChildren().add(test2);


        // SanSerif
        Text test3 = new Text(50, 100, "Java 7 Recipes");
        Font sanSerif = Font.font("SanSerif", 30);
        test3.setFont(sanSerif);
        test3.setFill(Color.BLUE);
        root.getChildren().add(test3);

        // Dialog
        Text test4 = new Text(50, 150, "Java 7 Recipes");
        Font dialogFont = Font.font("Dialog", 30);
        test4.setFont(dialogFont);
        test4.setFill(Color.rgb(0, 255, 0));
        root.getChildren().add(test4);

        // Monospaced
        Text test5 = new Text(50, 200, "Java 7 Recipes");
        Font monoFont = Font.font("Monospaced", 30);
        test5.setFont(monoFont);
        test5.setFill(Color.BLACK);
        root.getChildren().add(test5);

        Reflection refl = new Reflection();
        refl.setFraction(0.8f);
        test5.setEffect(refl);

        primaryStage.setScene(scene);
        primaryStage.show();
    }
}



PreviousNext

Related