How to set scrollbar of scrollpane for label

11,294

I think this is for sample code in text wrapping using scroll pane.Just refer this.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package comboboxeditable;

import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 *
 * @author reegan
 */
public class TextWrapping extends Application {

    Node sub;

    @Override
    public void start(Stage primaryStage) {
        ScrollPane root = new ScrollPane();
        Scene scene = new Scene(root, 300, 250);
        Text text = new Text("The look and feel of JavaFX applications "
                + "can be customized. Cascading Style Sheets (CSS) separate "
                + "appearance and style from implementation so that developers can "
                + "concentrate on coding. Graphic designers can easily "
                + "customize the appearance and style of the application "
                + "through the CSS. If you have a web design background,"
                + " or if you would like to separate the user interface (UI) "
                + "and the back-end logic, then you can develop the presentation"
                + " aspects of the UI in the FXML scripting language and use Java "
                + "code for the application logic. If you prefer to design UIs "
                + "without writing code, then use JavaFX Scene Builder. As you design the UI, "
                + "Scene Builder creates FXML markup that can be ported to an Integrated Development "
                + "Environment (IDE) so that developers can add the business logic.");
        text.wrappingWidthProperty().bind(scene.widthProperty());
        root.setFitToWidth(true);
        root.setContent(text);
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}
Share:
11,294
user3770144
Author by

user3770144

Updated on June 04, 2022

Comments

  • user3770144
    user3770144 almost 2 years

    I have guidance text in my app, which I put it in the label and is child of scrollpane. But the text is too long and I cannot by the scroll bar to get all text in the label. Any idea how to set the measure of scrollbar of scrollpane to get whole text in the label. I have used JavaFX Scene Builder.