Search code examples
stringjavafxjavafx-1

Label ends with ''..." in javafx 1.0


I put a string in a variabele and used it as text in a label. This works for shorter text, but my text is a few sentences long, so it ends with ... instead of finishing my string. I'm working with JavaFX 1.0. Does anyone know how i can fix this?

Edit: This is the code I wrote. I put the variable HandleidingDobbelsteen in a stage in an other file.

import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.control.Label;

package var DobbelsteenHandleiding = Label {
    text: "Hier komt te staan wat de uitkomst van de dobbelsteen betekent."
    translateX: 830
    translateY: 245
    width: 140
    textWrap: true;
}

package var HandleidingDobbelsteen = Group {
    content:[
        DobbelsteenHandleiding,
        Rectangle {
            x: 825, y: 220
            width: 150, height: 120
            fill: null
            stroke: Color.BLACK
            strokeWidth: 1.3
        },
        Rectangle {
            x: 825, y: 220
            width: 150, height: 20
            fill: Color.BLACK
        },
        Text {
            font : Font {size: 18}
            x: 845, y: 235
            content: "De regels"
            fill: Color.WHITE
        },
    ]
}

Solution

  • I am going to assume that your instructor is mistaken on the version of JavaFX they have you using. If they are correct, these instructions may not work for you (as I am not familiar with steam-powered Java)...

    The likely cause of your issue is that the String being used to set the Label's textProperty is longer than the Label is able to display. Without seeing your actual code, I have a couple of suggestions:

    First of all, make sure that your Label is wrapping its text:

    label.setWrapText(true);

    Secondly, you should make sure that the Label is wrapped in a layout container that can handle a node that grows (not always necessary, but recommended). My recommendation is a VBox:

    VBox vBox = new VBox(label);
    

    Again, there is some assumption here on the version of JavaFX you're actually using, but you could try this simple example to see if it works for you:

    import javafx.application.Application;
    import javafx.geometry.Insets;
    import javafx.geometry.Pos;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    
    public class Test extends Application {
    
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) {
    
            // Simple interface
            VBox vBox = new VBox(5);
            vBox.setPadding(new Insets(10));
            vBox.setAlignment(Pos.CENTER);
    
            Label label = new Label();
    
            // Let's add some very long text to our Label
            label.setText("This is long text. It doesn't mean much because I am just writing things to make it long. Yes, I am that clever. Don't you just love this? Neither do I!");
    
            // Make sure the Label is setup to wrap text when it reaches the end of its boundaries
            label.setWrapText(true);
    
            // Add the Label to our VBox
            vBox.getChildren().add(label);
    
            // Show the Stage
            primaryStage.setWidth(300);
            primaryStage.setHeight(300);
            primaryStage.setScene(new Scene(vBox));
            primaryStage.show();
        }
    }
    

    Result:

    screenshot 1


    To confirm that label.setWrapText(true); actually makes a difference, here's the result of the above code without that line, complete with the elipses ("...") you're experiencing:

    screenshot 2