gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:37:14 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com