سؤال

Am developing an application in Java FX. In this particular window I used BorderPane. The code provided below is supposed to display in the Center region of BorderPane when a button is pressed.

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;

}

The code is working. The details in the code is getting displayed at the Center region when the button is pressed. But the problem is that both the Label contents are not fully displayed. I will provide a screen shot.

enter image description here

So why the contents of the Label is not displaying fully ? How can I make it fully visible ?

هل كانت مفيدة؟

المحلول

That is because there is no enough space to show all text, and VBox will resize its children to their preferred size where the labels just hides their overflowed texts. To see the used layouts' borders (with their paddings applied) visually try:

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

and so on..

As a solution:
1) Enlarge the window size or reduce paddings/insets.
2) Force the labels to show all text by giving min height lb1.setMinHeight(70);.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top