请不要真的知道我在做错了什么我将listview的选择模式设置为多选模式但是当我运行代码时我仍然无法进行多项选择
这段代码来自登录窗口的mainController类,它有列表视图
try {
Stage st = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
Parent sceneMain = loader.load();
mainController controller = loader.<mainController>getController();
Scene scene = new Scene(sceneMain);
st.setScene(scene);
st.setTitle("Window that contains the listView");
st.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
st.show();
((Node)event.getSource()).getScene().getWindow().hide();
} catch (IOException ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
}
下面的是mainControler类
@FXML ListView<String> listViewReg;
@FXML ListView<String> listViewUnReg;
public void txtNumKeyRel(KeyEvent event){
if(txtRegNo.getText().length()==10){
populateListViews();
statusMessage("["+txtRegNo.getText().toUpperCase()+"]"+" details loaded", "success");
}
}
}
填充列表方法
public void populateListViews(){
ObservableList<String> listViewRegitems = FXCollections.observableArrayList(regSub);
listViewReg.setItems(listViewRegitems.sorted());
listViewReg.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
ObservableList<String> listViewUnRegItems= FXCollections.observableArrayList(unRegSub);
listViewUnReg.setItems(listViewUnRegItems.sorted());
listViewUnReg.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
}