2023年5月18日12:26:54 修改音乐列表 添加 鼠标滑过样式

master
zhangmeng 2023-05-18 15:08:32 +08:00
parent cb2663e8c7
commit 5f4734f470
1 changed files with 18 additions and 6 deletions

View File

@ -581,15 +581,19 @@ public class MusicController {
}
public static final String color_cell = "#f4f4f4";
private void list_cell() {
listView.setCellFactory(new Callback<ListView<File>, ListCell<File>>() {
private int position;
Text text = null;
public ListCell<File> call(ListView<File> param) {
final ListCell<File> cell = new ListCell<File>() {
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<ActionEvent>() {
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"));