每当我的选择框选项更改时,我都无法显示网格窗格标签

时间:2019-01-11 11:22:17

标签: java javafx

我有一个用作日历的GridPane和一个ChoiceBox,它使用户可以选择他们想要查看的月份(例如1月,2月),并且我想添加一个标签来说明这一点;如果用户在选择框中选择1月,则只要瑜伽对象与用户在选择框中选择的月份相同,就应显示标签“瑜伽课”。

我已经尝试过使用do while循环和if条件,但是似乎没有一个起作用。

public void initialize () {

    dropdown.getItems().addAll("January","Febuary","March","April","May","June","July","August","September","October","November","December");

    dropdown.getSelectionModel().selectedItemProperty().addListener(new ChangeListener <String>() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            System.out.println(newValue);


            if (newValue == "January") {
                monthnumber = 1;
            }
            if (newValue == "Febuary") {
                monthnumber = 2;
            }
            if (newValue == "March") {
                monthnumber =3;
            }
            if (newValue == "April") {
                monthnumber =4;
            }
            if (newValue == "May") {
                monthnumber = 5;
            }
            if (newValue == "June") {
                monthnumber = 6;
            }
            if (newValue == "July") {
                monthnumber =7;
            }
            if (newValue == "August") {
                monthnumber =8;
            }
            if (newValue == "September") {
                monthnumber = 9;
            }
            if (newValue == "October") {
                monthnumber = 10;
            }
            if (newValue == "November") {
                monthnumber = 11;
            }
            if (newValue == "December") {
                monthnumber = 12;


            }

        }

    });

    Event yoga = new Event (12,"yoga class",1, "thedescription", "11-12");

    if (monthnumber == yoga.getmnth()) {
        Gpane.add(new Label(yoga.getname()),1 , yoga.getdate()+1);
    }

0 个答案:

没有答案