我的函数无法在 JavaFx 中调用

my function cant get called in JavaFx

我在 FXML 中创建了一个列表视图,其 ID 为 "lwAllUserGrp" 我可以使用该 ID 和以下函数来填充它:

public void populateAllUserList() {
        lwAllUserGrp.getItems().clear();
        ///////////////////////////////////////////////
        String filter = txtSearch.getText();
        String Query = "Select user_name, user_login_name, user_state from dm_user where r_is_group = 0 and user_state = 0  and (user_name not like 'dm%' and user_name not like 'svc%' and user_name not like 'lexo%' ) order by user_name";
        ArrayList<String> AllUser = GetDataWithDql(_session, Query, "user_name");
        for (String x : AllUser) {
            if (x.toLowerCase().contains(filter.toLowerCase())){

                lwAllUserGrp.getItems().add(x);

            }

        }
    }

但是当我添加以下函数以查看选择了哪一行时:

public void selectedItemFromListView(){
         //      System.out.println("blabla");
         selected = lwAllUserGrp.getSelectionModel().getSelectedItem();
//       System.out.println(selected);
         String Query = "select user_name , user_state , user_address, user_login_name , user_web_page from dm_user where user_name ='@aclname'";
         Query = Query.replace("@aclname",selected );
         ArrayList<User> allUserNames = GetDataWithDqlpro(_session, Query, "user_name","user_address","user_state","user_login_name","user_web_page");
         for (int i = 0 ; i < allUserNames.size() ; i++ ){
             if (selected.compareToIgnoreCase(allUserNames.get(i).getUsername() ) == 0){

                    username.setText(selected);
                    login_Name.setText(allUserNames.get(i).getuserLoginName());
                    state.setText(allUserNames.get(i).getState());
                    address.setText(allUserNames.get(i).getAddress());
                    WP.setText(allUserNames.get(i).getuserWP());
             }

         }


}

我的函数根本没有被调用?任何人都知道为什么?

如果您不调用该函数,它就不会自行调用 :) 您必须将其添加为侦听器或其他任何内容。在您的情况下,您缺少 FXML 中的侦听器分配(我有一种预感,这就是我问的原因)。正如您在评论中发现的那样,在您的 FXML 中添加适当的 onMouseClicked 说明符应该可以解决这个问题。