diff --git a/src/main/java/com/zhangmeng/tools/controller/MusicController.java b/src/main/java/com/zhangmeng/tools/controller/MusicController.java index 5460757..3d48fa3 100644 --- a/src/main/java/com/zhangmeng/tools/controller/MusicController.java +++ b/src/main/java/com/zhangmeng/tools/controller/MusicController.java @@ -581,15 +581,19 @@ public class MusicController { } + public static final String color_cell = "#f4f4f4"; + private void list_cell() { listView.setCellFactory(new Callback, ListCell>() { + private int position; + Text text = null; public ListCell call(ListView param) { final ListCell cell = new ListCell() { protected void updateItem(File item, boolean empty) { super.updateItem(item, empty); if (!empty && item != null) { + text = new Text(sb.substring(0, sb.length() - 4)); sb = new StringBuffer(item.getName()); - Text text = new Text(sb.substring(0, sb.length() - 4)); text.setWrappingWidth(300.0D); text.setTextAlignment(TextAlignment.CENTER); if (this.getIndex() == MusicController.this.playindex.get()) { @@ -611,6 +615,19 @@ public class MusicController { } }; + + cell.hoverProperty().addListener((observableValue, aBoolean, t1) -> { + if (t1 && !text.getText().equals("")) { + position = listView.getItems().indexOf(text.getText()); + text.setFont(new Font(16)); + listView.getFocusModel().focus(position); + cell.setStyle("-fx-background-color: #369e7d"); + } else { + text.setFont(new Font(13)); + cell.setStyle("-fx-background-color: " + color_cell); + } + }); + MenuItem mi1 = new MenuItem("从列表中移除"); mi1.setOnAction(new EventHandler() { public void handle(ActionEvent event) { @@ -698,11 +715,6 @@ public class MusicController { return null; } - - - - - public static void addDir(File file) { File[] addfiles = file.listFiles((dir, name) -> name.endsWith("mp3"));