setWrapText(true)在JavaFX中不适用于Label [英] setWrapText(true) is not working for Label in JavaFX

查看:482
本文介绍了setWrapText(true)在JavaFX中不适用于Label的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaFX中创建了一个Label,其中包含很多文本.

I created a Label in JavaFX which has a contains a lot of text.

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)不起作用.为什么?我该如何运作?

In this code setWrapText(true) is not working. Why? How can I make it work?

推荐答案

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

结果

这篇关于setWrapText(true)在JavaFX中不适用于Label的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆