0

I tortured google with multiple questions but still cant get a point.

I want to build app with 2 FXML scenes populated by SceneBuilder. Each have it's own controller. I use ControlledScreen to swap Scenes and this works. But then i cant change anything on scene. For example: i have label in Scene Controller:

    public class ControllerForm implements ControlledScreen, Initializable {

    ScreensController myController;
        GraphicsContext GC;

         @FXML
            private Label fitnessLabel;

public void updateFitnessLabel(double data) {
                fitnessLabel.setText(String.valueOf(data));
            }

public void initialize(URL location, ResourceBundle resources) {
            this.GC = neuroCanvas.getGraphicsContext2D();
               }

It's defined in FXML file as:

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="684.0" prefWidth="918.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="general.ControllerForm">
   <left>
      <VBox prefHeight="400.0" prefWidth="189.0" BorderPane.alignment="CENTER">
         <children>
    <Label fx:id="fitnessLabel" text="Label">
                   <graphic>
                      <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Fitness:" />
                   </graphic>
                </Label>

And function to update label is updateFitnessLabel.

In initialize method i use GC cuz i have canvas on this scene and want to draw on it.

I have method that is calling for this fucntion as:

public class Net {
private ControllerForm controller;

    public void drawStart() throws IOException {
     FXMLLoader loader = new FXMLLoader(
                        getClass().getResource(
                                Main.ScreenFile
                        )
                );

                BorderPane cv =  loader.load();
                // load actual screen
                ControllerForm controller =
                        loader.<ControllerForm>getController();

                controller.updateFitnessLabel(12);}

But no effect. Label wont be updated.

What am i missing ?

I tried to use Timeline, but still no effect. How to actuall draw something on this scene ?

SystemFailure
  • 67
  • 1
  • 9
  • 1
    It would help if you could provide more context. What does the FXML look like? Is there any other relevant controller code? – Greg Brown Jan 29 '16 at 20:34
  • Nothing more is relevant. FXML is standart. If i draw something in initialize it's appears so controller works. – SystemFailure Jan 29 '16 at 21:08
  • Without the FXML and additional code examples, it will be difficult to help diagnose your issue. – Greg Brown Jan 29 '16 at 21:17
  • That is all :D ControllerForm have much more lables but they all the same. i think i'm missing general idea of how to build applications like this but i'm unable to figure out what to look for. – SystemFailure Jan 29 '16 at 21:33
  • What do you see when you run the app? What does the label say? – Greg Brown Jan 29 '16 at 21:37
  • nothing, it's in default state - "label" – SystemFailure Jan 29 '16 at 22:48
  • I have a feeling that your actual screen content is being loaded and presented elsewhere and that this code is simply loading the markup, changing the label state, and exiting. Where is the code that actually puts the scene in the screen? – Greg Brown Jan 29 '16 at 23:43
  • 1
    @SystemFailure Please add a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) to your question. This makes it easier for people to debug and offer a solution to your question. – ItachiUchiha Jan 30 '16 at 07:02

1 Answers1

0

Ok, i found solution.

loader.load returns Object. But i need initial Object not a new one. Used this answer - FXMLLoader getController returns NULL?

This is not optimal, but i have no idea how to get initial object.

Community
  • 1
  • 1
SystemFailure
  • 67
  • 1
  • 9