How to set scrollbar of scrollpane for label


Question

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.

1
2
10/3/2014 5:36:26 PM

Accepted Answer

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);
    }

}
4
10/4/2014 9:25:03 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon