@FXML private void Play(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { if (j == 0) { listView.getSelectionModel().select(j); listView.getFocusModel().focus(j); } if (mp != null) { MediaPlayer.Status status = mp.getStatus(); if (status == MediaPlayer.Status.UNKNOWN || status == MediaPlayer.Status.HALTED) { return; } if (status == MediaPlayer.Status.PAUSED || status == MediaPlayer.Status.READY || status == MediaPlayer.Status.STOPPED) { if (atEndOfMedia) { atEndOfMedia = false; } onPlay(); mp.play(); statusDisplay.toBack(); play = true; } else { mp.pause(); statusDisplay.toFront(); play = false; } } } }
/** * A Popup containing Listview is trigged from this function This function automatically resize * it's height and width according to the width of textbox and item's cell height */ public void showPopup(String newValue) { ListView<String> listView = new ListView<>(); listView.setPrefWidth(textField.getWidth()); listView.getSelectionModel().clearSelection(); listView.getFocusModel().focus(-1); listView.setItems(searchItems(newValue)); // Set ListView height if (listView.getItems().size() > getDefaultLimitCount()) { listView.setPrefHeight(getDefaultLimitCount() * getDefaultPrefHeight()); } else { listView.setPrefHeight(listView.getItems().size() * getDefaultPrefHeight()); } listView.setOnMouseReleased( event -> { textField.setText(listView.getSelectionModel().getSelectedItem()); textField.requestFocus(); textField.requestLayout(); textField.end(); popup.hide(); onSelectAction(listView.getSelectionModel().getSelectedItem()); }); listView.setOnKeyReleased( event -> { switch (event.getCode()) { case ENTER: textField.setText(listView.getSelectionModel().getSelectedItem()); textField.requestFocus(); textField.requestLayout(); textField.end(); popup.hide(); onSelectAction(listView.getSelectionModel().getSelectedItem()); break; default: break; } }); // This cell factory helps to know which cell has been selected so that // when ever any cell is selected the textbox rawText must be changed listView.setCellFactory( view -> { // A simple ListCell containing only Label final ListCell<String> cell = new ListCell<String>() { public void updateItem(String item, boolean empty) { super.updateItem(item, empty); setText(item); } }; return cell; }); popup.getContent().clear(); popup.getContent().add(listView); // SHOWING THE POPUP JUST BELOW TEXTBOX popup.show( getWindow(), getWindow().getX() + textField.localToScene(0, 0).getX() + textField.getScene().getX(), getWindow().getY() + textField.localToScene(0, 0).getY() + textField.getScene().getY() + getDefaultPrefHeight()); }