I'm writing a program with a combobox in which you can select different professors. After a selection is made you click a "GO" button and go to a new scene. However, the .getSelectedItem() method doesn't compile. If I use .getSelectionModel().getSelectedItem() it runs but it doesn't work.

I've tried the .getItem() and .getValue() methods as well. I used to have the code all in one method but I need to pass it so I created a new method that is called from the method with the event. I also tried calling the method from the method with the "GO" button.

These are the two methods to get the selection:

public void InstructorSelected(ActionEvent event)
{

    String instructorSelected = determineSelection();
    System.out.println(instructorSelected);

}
public String determineSelection()
{

    String selection = combobox.getSelectionModel().getSelectedItem();

    return selection;

}

And here is the event method that loads the third scene when you click the second "GO" button:

public void goToCourseViewButtonPushed(ActionEvent event) throws IOException 
{
        Parent CourseViewParent = 
        FXMLLoader.load(getClass().getResource("CourseView.fxml"));
        Scene CourseViewScene = new Scene (CourseViewParent);

        Stage CourseWindow = (Stage) 
        ((Node)event.getSource()).getScene().getWindow();

        CourseWindow.setScene(CourseViewScene);
        CourseWindow.show();
} 

I need to get the selection and store it a variable because I then need to use it to get data from a database but only the ones for that professor. If use this methods the program gets stuck when I try to load a new scene. However, if instead of getting the selection from the combobox I just pass a String then it works fine so the problem isn't with loading the other scene.

0 Answers