Fill label automatically when stage opens - JavaFX

0

I need a label to receive text automatically as soon as stage is started, without having to click a button. Because different texts are saved in a database, they need to be loaded into the label when stage starts.

Is there a method for this?

This is the controller class of the application:

public class DesafioController {
    @FXML Button btnCancelar = new Button();
    @FXML TextArea AreaSolucao = new TextArea();
    @FXML Label labelDesafio = new Label();
    @FXML AnchorPane pane = new AnchorPane();

    @FXML
    void clickRecomecar() {
        //Reinicia o desafio do zero, apagando o que já foi escrito.
        AreaSolucao.setText("TESTE RECOMEÇAR");
    }

    @FXML
    void clickCancelar() {
        //Fecha o desafio voltando para o jogo.
        Stage atual = (Stage) btnCancelar.getScene().getWindow();
        atual.close();
    }

    @FXML
    void clickEnviar() {
        //Aqui será enviado a solução do desafio para o banco de dados.(INSERT)
    }
}

Application window:

    
asked by anonymous 25.11.2017 / 19:50

1 answer

0

You can override the behavior of the initialize() ", which is briefly the method called when all the controls annotated by @FXML are injected. To do this, your control class must implement Initializable : / p>

public class DesafioController implements Initializable {

   private @FXML Label label;

   @Override
   public void initialize(URL url, Resources res)
      label.setText("Texto Inicial.");
   }
}
    
27.11.2017 / 00:17