1

I am trying to display different content in a certain scene based on the button the user selects in the previous scene. I have tried using public static void main(String[] args) and timers to get this to work, but I just can't.

How do I get contentSelect() to run upon the opening of the scene? I know this should be simple, but I cannot get it to work for the life of me.

package application;

import java.time.Duration;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;

public class GrammarTestController {

    private static int picSelect=0;
    @FXML
    private Label title;
    @FXML
    private Label info;
    @FXML
    private ImageView image;

    //Will decide which type of content to display
    private void contentSelect(){


    }
}
ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
A Tir
  • 51
  • 1
  • 2
  • 2
    If `GrammarTestController` is the controller of the popup scene, you can call `contentSelect()` in the `initialize()` method of the controller, as that method is called automatically by the `FXMLLoader`. – DVarga Mar 22 '17 at 06:25
  • Hi! Thanks for your answer! But it is still not working. – A Tir Mar 22 '17 at 12:55
  • private void initialize(){ System.out.println("plz yes"); } – A Tir Mar 22 '17 at 12:55
  • ^ I added that to the middle of my code, but nothing prints when I open the the view for GrammarTestController. Am I doing something wrong? – A Tir Mar 22 '17 at 12:57
  • It also says this: "The method initialize() from the type GrammarTestController is never used locally:" – A Tir Mar 22 '17 at 12:58
  • I would pass the some data to the new controller. I would use that data to determine which method to run. http://stackoverflow.com/questions/30814258/javafx-pass-parameters-while-instantiating-controller-class – SedJ601 Mar 22 '17 at 13:22

1 Answers1

0

Implement Initializable:

public class GrammarTestController implements Initializable{
    private static int picSelect=0;
    @FXML
    private Label title;
    @FXML
    private Label info;
    @FXML
    private ImageView image;

    //This method is called upon fxml load
    public void initialize(URL location, ResourceBundle resources) {
        contentSelect();
    }

    //Will decide which type of content to display
    private void contentSelect(){


    }
}
g0rdonL
  • 301
  • 1
  • 3
  • 14