From 2c43728b0275a29cc728cd7fb73d0c1713bb4686 Mon Sep 17 00:00:00 2001 From: KSSJW <165921128+KSSJW@users.noreply.github.com> Date: Sat, 27 Jun 2026 21:41:02 +0800 Subject: [PATCH 1/3] Fix: FontComboBox closes unexpectedly --- .../hmcl/ui/construct/FontComboBox.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java index 64ffda3317e..61dfc2e77f7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java @@ -28,6 +28,9 @@ import com.jfoenix.controls.JFXListCell; import javafx.beans.binding.Bindings; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.control.skin.ComboBoxListViewSkin; import javafx.scene.text.Font; public final class FontComboBox extends JFXComboBox { @@ -61,5 +64,22 @@ public void updateItem(String item, boolean empty) { setItems(observableList(Font.getFamilies())); loaded = true; }); + + skinProperty().addListener((obs, oldSkin, newSkin) -> { + if (!(newSkin instanceof ComboBoxListViewSkin skin)) { + return; + } + + skin.setHideOnClick(false); + + @SuppressWarnings("unchecked") + ListView listView = (ListView) skin.getPopupContent(); + + listView.setOnMouseClicked(e -> { + if (e.getTarget() instanceof ListCell) { + hide(); + } + }); + }); } } From dc7f35b0ebc26f23ae0e7fac8204ac5a29ac950f Mon Sep 17 00:00:00 2001 From: KSSJW <165921128+KSSJW@users.noreply.github.com> Date: Sat, 27 Jun 2026 21:54:26 +0800 Subject: [PATCH 2/3] Refactor: FontComboBox target node judge --- .../java/org/jackhuang/hmcl/ui/construct/FontComboBox.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java index 61dfc2e77f7..cc0f6ee0683 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java @@ -28,6 +28,7 @@ import com.jfoenix.controls.JFXListCell; import javafx.beans.binding.Bindings; +import javafx.scene.Node; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.skin.ComboBoxListViewSkin; @@ -76,7 +77,11 @@ public void updateItem(String item, boolean empty) { ListView listView = (ListView) skin.getPopupContent(); listView.setOnMouseClicked(e -> { - if (e.getTarget() instanceof ListCell) { + Node target = e.getTarget() instanceof Node ? (Node) e.getTarget() : null; + while (target != null && !(target instanceof ListCell)) { + target = target.getParent(); + } + if (target instanceof ListCell cell && !cell.isEmpty()) { hide(); } }); From 106d7c4a9ebeeceeee2ce0a9feb8c476fd7c43c8 Mon Sep 17 00:00:00 2001 From: KSSJW <165921128+KSSJW@users.noreply.github.com> Date: Sat, 27 Jun 2026 22:04:32 +0800 Subject: [PATCH 3/3] Refactor: FontComboBox safety --- .../hmcl/ui/construct/FontComboBox.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java index cc0f6ee0683..96f436ab406 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java @@ -73,18 +73,17 @@ public void updateItem(String item, boolean empty) { skin.setHideOnClick(false); - @SuppressWarnings("unchecked") - ListView listView = (ListView) skin.getPopupContent(); - - listView.setOnMouseClicked(e -> { - Node target = e.getTarget() instanceof Node ? (Node) e.getTarget() : null; - while (target != null && !(target instanceof ListCell)) { - target = target.getParent(); - } - if (target instanceof ListCell cell && !cell.isEmpty()) { - hide(); - } - }); + if (skin.getPopupContent() instanceof ListView listView) { + listView.addEventHandler(javafx.scene.input.MouseEvent.MOUSE_CLICKED, e -> { + Node target = e.getTarget() instanceof Node ? (Node) e.getTarget() : null; + while (target != null && !(target instanceof ListCell)) { + target = target.getParent(); + } + if (target instanceof ListCell cell && !cell.isEmpty()) { + hide(); + } + }); + } }); } }