如何为标签设置滚动条的滚动条

时间:2014-10-03 17:36:26

标签: javafx label scrollpane

我的应用程序中有指导文本,我将其放在标签中,并且是滚动窗格的子项。但是文本太长了,我不能通过滚动条来获取标签中的所有文本。知道如何设置scrollpane滚动条的度量以获得标签中的全文。 我使用过JavaFX Scene Builder。

1 个答案:

答案 0 :(得分:4)

我认为这是使用滚动窗格进行文本换行的示例代码。请参阅此内容。

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

}