Friday, May 4, 2012

JavaFX - Create ScrollPane using ScrollPaneBuilder

Create ScrollPane using ScrollPaneBuilder


package javafx_text;

import javafx.application.Application;
import javafx.geometry.VPos;
import javafx.scene.Group;
import javafx.scene.GroupBuilder;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPaneBuilder;
import javafx.scene.paint.Color;
import javafx.scene.shape.RectangleBuilder;
import javafx.scene.text.*;
import javafx.stage.Stage;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFX_Text extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("java-buddy.blogspot.com");
        Group root = new Group();
        
        String Santa_Claus_Is_Coming_To_Town =
                "You better watch out\n"
                + "You better not cry\n"
                + "Better not pout\n"
                + "I'm telling you why\n"
                + "Santa Claus is coming to town\n"
                + "\n"
                + "He's making a list\n"
                + "And checking it twice;\n"
                + "Gonna find out Who's naughty and nice\n"
                + "Santa Claus is coming to town\n"
                + "\n"
                + "He sees you when you're sleeping\n"
                + "He knows when you're awake\n"
                + "He knows if you've been bad or good\n"
                + "So be good for goodness sake!\n"
                + "\n"
                + "O! You better watch out!\n"
                + "You better not cry\n"
                + "Better not pout\n"
                + "I'm telling you why\n"
                + "Santa Claus is coming to town\n"
                + "Santa Claus is coming to town\n";
        
        Text textSong = TextBuilder.create()
                .text(Santa_Claus_Is_Coming_To_Town)
                .layoutX(50)
                .textOrigin(VPos.TOP)
                .textAlignment(TextAlignment.JUSTIFY)
                .fill(Color.BLUE)
                .font(Font.font("SansSerif", FontPosture.ITALIC, 18))
                .build();
        
        Group myGroup = GroupBuilder.create()
                .children(
                    ScrollPaneBuilder.create()
                        .prefWidth(500)
                        .prefHeight(100)
                        .content(textSong)
                        .build()
                )
                .build();
        
        root.getChildren().add(myGroup);
  
        primaryStage.setScene(new Scene(root, 500, 400));
        primaryStage.show();
    }
}


No comments:

Post a Comment