Javafx 标签未在Java FX中显示完整内容

Javafx 标签未在Java FX中显示完整内容,javafx,javafx-2,label,javafx-8,Javafx,Javafx 2,Label,Javafx 8,我正在用JavaFX开发一个应用程序。在这个特定的窗口中,我使用了BorderPane。按下按钮时,下面提供的代码应该显示在BorderPane的中心区域 private VBox tutor() { VBox vb1 = new VBox(); vb1.setPadding(new Insets (80, 50, 50, 160)); vb1.setSpacing(30); VBox vb2 = new VBox(); vb2.setPadding(

我正在用JavaFX开发一个应用程序。在这个特定的窗口中,我使用了BorderPane。按下按钮时,下面提供的代码应该显示在BorderPane的中心区域

private VBox tutor() {

    VBox vb1 = new VBox();
    vb1.setPadding(new Insets (80, 50, 50, 160));
    vb1.setSpacing(30);

    VBox vb2 = new VBox();
    vb2.setPadding(new Insets (30, 30, 30, 30));
    vb2.setSpacing(10);

    Label lb1 = new Label("New Tutor...? Sign Up here by providing the\n"
            + "necessary details in the next page. Press the 'Sign Up'\n"
            + "button to proceed.");
    lb1.setFont(Font.font("Calibri", FontWeight.BOLD, 17));
    lb1.setTextFill(Color.BLACK);

    Button btnacnt = new Button("Sign Up");
    btnacnt.setFont(Font.font("Calibri", FontWeight.THIN, 18));
    btnacnt.setStyle(" -fx-base: #333333;");
    btnacnt.setTextFill(Color.WHITE);

    vb2.getChildren().addAll(lb1, btnacnt);

    VBox vb3 = new VBox();
    vb3.setPadding(new Insets (30, 30, 30, 30));
    vb3.setSpacing(10);

    Label lb2 = new Label("Existing Tutor...? Sign In here by providing the\n"
            + "username and password in the next page. Press the 'Sign In'\n"
            + "button to proceed.");
    lb2.setFont(Font.font("Calibri", FontWeight.BOLD, 17));
    lb2.setTextFill(Color.BLACK);

    Button btnsignin = new Button("Sign In");
    btnsignin.setFont(Font.font("Calibri", FontWeight.THIN, 18));
    btnsignin.setStyle(" -fx-base: #333333;");
    btnsignin.setTextFill(Color.WHITE);

    btnsignin.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            setCenter(tutorSignin());
        }
    });

    vb3.getChildren().addAll(lb2, btnsignin);

    vb1.getChildren().addAll(vb2, vb3);
    return vb1;

}
private VBox tutor(){
VBox vb1=新的VBox();
vb1.设置填充(新插图(80、50、50、160));
vb1.setspace(30);
VBox vb2=新的VBox();
vb2.设置填充(新的插图(30,30,30,30));
vb2.setspace(10);
Label lb1=新标签(“新导师…?通过提供以下内容在此处注册\n”
+“下一页中的必要详细信息。请按“注册”\n”
+“按钮继续。”);
lb1.setFont(Font.Font(“Calibri”,fontwweight.BOLD,17));
lb1.setTextFill(颜色为黑色);
按钮btnacnt=新按钮(“注册”);
setFont(Font.Font(“Calibri”,fontwweight.THIN,18));
btnacnt.setStyle(“-fx base:#333333;”);
btnacnt.setTextFill(颜色为白色);
vb2.getChildren().addAll(lb1,btnacnt);
VBox vb3=新的VBox();
vb3.设置填充(新插图(30,30,30,30));
vb3.setspace(10);
Label lb2=新标签(“现有导师…?通过提供以下信息在此登录\n”
+“下一页的用户名和密码。请按“登录”\n”
+“按钮继续。”);
lb2.setFont(Font.Font(“Calibri”,fontwweight.BOLD,17));
lb2.setTextFill(颜色为黑色);
按钮btnsignin=新按钮(“登录”);
btnsignin.setFont(Font.Font(“Calibri”,fontwweight.THIN,18));
btnsignin.setStyle(“-fx base:#333333;”);
btnsignin.setTextFill(颜色为白色);
setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent e){
设置中心(tutorSignin());
}
});
vb3.getChildren().addAll(lb2,btnsignin);
vb1.getChildren().addAll(vb2,vb3);
返回vb1;
}
代码正在运行。按下按钮时,代码中的详细信息将显示在中心区域。但问题是两个标签内容都没有完全显示出来。我将提供一个屏幕截图


那么为什么标签的内容没有完全显示出来呢?如何使其完全可见?

这是因为没有足够的空间来显示所有文本,VBox会将其子项调整为其首选大小,而标签只是隐藏溢出的文本。要直观地查看使用过的布局的边框(应用了填充),请尝试:

vb1.setStyle("-fx-border-color:red");
vb2.setStyle("-fx-border-color:green");
vb3.setStyle("-fx-border-color:blue");
lb1.setStyle("-fx-border-color:yellow");
lb2.setStyle("-fx-border-color:aqua");
等等

作为解决方案:
1) 放大窗户尺寸或减少填充物/镶嵌物。

2) 通过给出最小高度
lb1.setMinHeight(70),强制标签显示所有文本

@AnshulParashar不要将答案作为注释。@LimitedAtoniment收到了!!