Home » Java Codes

JavaFX – Different text effects in JavaFX

13 February 2009 195 views No Comment

Some of the way, we can make fancy text. There are lot of good way but these are few of them. If you really want to make it fancy then please do some R&D with these API’s used in this code. Here is a small code:

package addingfontinstyle;   

import javafx.scene.effect.DropShadow;   
import javafx.scene.effect.GaussianBlur;   
import javafx.scene.effect.light.DistantLight;   
import javafx.scene.effect.light.SpotLight;   
import javafx.scene.effect.Lighting;   
import javafx.scene.paint.Color;   
import javafx.scene.Scene;   
import javafx.scene.text.Font;   
import javafx.scene.text.FontWeight;   
import javafx.scene.text.Text;   
import javafx.scene.text.TextOrigin;   
import javafx.stage.Stage;   

  

Stage {   
    title: “Text In Style”  
    width: 450  
    height: 500  
    scene: Scene {   
        content: [   
            Text {   
                effect: DropShadow {   
                    offsetX: -10  
                    offsetY: -10  
                }   

                font: Font {   
                    name: "Arial"  
                    letterSpacing: 0.20  
                    size: 50  
                }   
                fill: Color.YELLOWGREEN   
                stroke: Color.GREEN,   
                strokeWidth: 3  
                x: 15,   
                y: 80  
                content: "Hello World"  
            },   

                Text {   
                effect: Lighting {   
                    light: DistantLight {   
                        azimuth: -135  
                        elevation: 30  
                    }   
                    surfaceScale: 5  
                }   
                x: 10  
                y: 200  
                content: "Hello World"  
               fill: Color.RED   
                font: Font {   
                    name: "Arial Bold"  
                    letterSpacing: 0.20  
                    size: 50  
                }   
            },   
            Text {   
                effect: Lighting {   
                    light: SpotLight {   
                        x: 0  
                        y: 100  
                        z: 50  
                        pointsAtX: 400  
                        pointsAtY: 0  
                        pointsAtZ: 0  
                        specularExponent: 2  
                    }   
                    surfaceScale: 5  
                }   
                textOrigin: TextOrigin.TOP   
                x: 10  
                y: 300  
                content: "Hello World"  
                fill: Color.RED   
                font: Font {   
                    name: "Arial Bold"  
                    letterSpacing: 0.20  
                    size: 50  
                }   
            },   
            Text {   
                effect: GaussianBlur {   
                }   
                x: 10  
                y: 400  
                content: "Hello World"  
                fill: Color.GREEN   
                font: Font {   
                    name: "Arial Bold"  
                    letterSpacing: 0.20  
                    size: 50  
                }   
            }   
        ]   
    }   
}  


Tags: , , , , , , , , , , , , , , , , , , , , , , , ,

Leave your response!

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>