From 5f4734f470c566e56a395391e28c4071d289508c Mon Sep 17 00:00:00 2001 From: zhangmeng <1334717033@qq.com> Date: Thu, 18 May 2023 15:08:32 +0800 Subject: [PATCH] =?UTF-8?q?2023=E5=B9=B45=E6=9C=8818=E6=97=A512:26:54=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9F=B3=E4=B9=90=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E9=BC=A0=E6=A0=87=E6=BB=91=E8=BF=87?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/controller/MusicController.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) 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"));