我在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)
无效。为什么?我怎样才能使它发挥作用?
答案 0 :(得分:13)
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);
}
}
导致
答案 1 :(得分:0)
我在Scene Builder中遇到了相同的问题,而其他解决方案均无效。
我终于通过将“最小高度”设置为USE_PREF_SIZE
并保持“前身高度”为USE_COMPUTED_SIZE
来使其工作。
这将转换为F minHeight
属性设置为-Infinity
的FXML。