javafx - setWrapText(true) 不适用于 JavaFX 中的 Label

标签 javafx label javafx-2

我在 JavaFX 中创建了一个 Label,其中包含大量文本。

Label l1 = new Label("\t\tC-Mark and Attendance Calculator is a simple "
            + "software to find both the C-Mark and monthly attendance "
            + "of students. Inorder to use the features of this software,"
            + " user has to create an account for him first. Then he should "
            + "login using the username and password. He will be able to "
            + "perform all the operations then. Further details are mentioned"
            + " in the 'HELP' section in the user home page.");
l1.setWrapText(true);
l1.setTextAlignment(TextAlignment.JUSTIFY);

在此代码中 setWrapText(true) 不起作用。为什么?我怎样才能让它发挥作用?

最佳答案

Label l1 = new Label("\t\tC-Mark and Attendance Calculator is a simple "
                + "software to find both the C-Mark and monthly attendance "
                + "of students. Inorder to use the features of this software,"
                + " user has to create an account for him first. Then he should "
                + "login using the username and password. He will be able to "
                + "perform all the operations then. Further details are mentioned"
                + " in the 'HELP' section in the user home page.");
        l1.setWrapText(true);
        l1.setTextAlignment(TextAlignment.JUSTIFY);

这是一个 SSCCE:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;

public class WrappedLabelExample extends Application {

    @Override
    public void start(Stage primaryStage) {
        Label l1 = new Label("\t\tC-Mark and Attendance Calculator is a simple "
                + "software to find both the C-Mark and monthly attendance "
                + "of students. Inorder to use the features of this software,"
                + " user has to create an account for him first. Then he should "
                + "login using the username and password. He will be able to "
                + "perform all the operations then. Further details are mentioned"
                + " in the 'HELP' section in the user home page.");
        l1.setWrapText(true);
        l1.setTextAlignment(TextAlignment.JUSTIFY);

        StackPane root = new StackPane(l1);
        root.setPadding(new Insets(10));
        Scene scene = new Scene(root, 400, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

结果

enter image description here

关于javafx - setWrapText(true) 不适用于 JavaFX 中的 Label,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22350767/

相关文章:

javafx - tableView标题的高度

java - 你能在 JavaFX 中使用字体连字吗

ios - 无法在 Swift 4 中将值打印到标签。展开可选值错误时意外发现 nil

Javafx 在 TableView 中添加图像

JavaFX 平滑动画

javafx - 如何为javafx线同时设置颜色、宽度和绘制虚线?

java - 进度指示器仍然不确定并且没有下载

java - 可以设置矩形样式以显示边框吗?

java - Eclipse Java 8 错误 : Label cannot be resolved

python - matplotlib 修剪刻度标签