Set fill and font for Text : Text « JavaFX « Java






Set fill and font for Text

 

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application
{
   @Override
   public void start(final Stage stage) throws Exception
   {
      Group rootGroup = new Group();
      Scene scene =new Scene(rootGroup, 800, 400);
 
      Text text1 = new Text(25, 25, "java2s.com");
      text1.setFill(Color.CHOCOLATE);
      text1.setFont(Font.font(java.awt.Font.SERIF, 25));
      rootGroup.getChildren().add(text1);

      stage.setScene(scene);
      stage.show();
   }
   public static void main(final String[] arguments)
   {
      Application.launch(arguments);
   }
}

   
  








Related examples in the same category

1.Create Static Text control and set color
2.Rotate a Text
3.Text with DropShadow
4.Text with CHOCOLATE color and Font.SERIF
5.Line breaking for Text
6.Reflection effect on text
7.Binding Stage x, y, width, height to Text control
8.Text wrapping width
9.Set Text Font
10.Text class defines a node that displays a text
11.Reflected Text
12.Text Effect show off
13.Paragraphs are separated by '\n' and the text is wrapped on paragraph boundaries.