1

This is the "console" version of what I want to do:

    String aboutMe;
    aboutMe = "bla bla bla";
    System.out.println(aboutMe);

and in JavaFX I have this:

in x.fxml:

    <Label GridPane.rowIndex="1" fx:id="about"/>

in Controller.java:

    public String aboutMe = "Bla bla";
    public Label about;

I would like to just use "text=aboutMe" in fmxl...but that's not working.

using

    public label about = new Label(aboutMe);

...isn't working either.

if I had a contructor I could do:

    public Controller() {
        about.setText(aboutMe);
    }

But I don't.

Any one have any ideas?

  • You have to use text="aboutMe" instead of "text=aboutMe" – jns Apr 23 '16 at 19:30
  • aboutMe is the String variabel I want to use, not the text. – Thomas Johansson Apr 23 '16 at 19:31
  • When you have a reference `@FXML private Label label` in `Controller`you can set the value like: `label.setText(aboutMe)`. The problem is you assign a new reference to label and set the value on that new reference instead of the one in your fxml file. If you need a reference to `Controller` you can have a look [here](http://stackoverflow.com/questions/12935953/javafx-class-controller-scene-reference?lq=1) – jns Apr 23 '16 at 19:47

1 Answers1

2

I got it to work using this:

public class Controller implements Initializable {


public void initialize(URL location, ResourceBundle resources) {
    about.setText(aboutMe);
}

}