From d2ae41c9ae8629c86ffe9c7c18ecc517828c5c81 Mon Sep 17 00:00:00 2001 From: Glavo Date: Tue, 27 Jan 2026 20:40:07 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20#5280:=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=88=97=E8=A1=A8=E9=A1=B5=E9=9D=A2=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E6=A8=AA=E5=90=91=E6=BB=9A=E5=8A=A8=E6=9D=A1=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#5284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/jackhuang/hmcl/ui/FXUtils.java | 14 ++++++++++++++ .../jackhuang/hmcl/ui/main/JavaManagementPage.java | 7 +++++-- .../hmcl/ui/versions/DownloadListPage.java | 7 ++----- HMCL/src/main/resources/assets/css/root.css | 7 +++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java index 0a1ade2f2..a24e5ab9b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -433,6 +433,20 @@ public final class FXUtils { return pane; } + public static void limitCellWidth(ListView listView, ListCell cell) { + ReadOnlyDoubleProperty widthProperty; + + if (listView.lookup(".clipped-container") instanceof Region clippedContainer) { + widthProperty = clippedContainer.widthProperty(); + } else { + widthProperty = listView.widthProperty(); + } + + cell.maxWidthProperty().bind(widthProperty); + cell.prefWidthProperty().bind(widthProperty); + cell.minWidthProperty().bind(widthProperty); + } + public static void smoothScrolling(ScrollPane scrollPane) { if (AnimationUtils.isAnimationEnabled()) ScrollUtils.addSmoothScrolling(scrollPane); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/JavaManagementPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/JavaManagementPage.java index 1465c9bab..90363c91c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/JavaManagementPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/JavaManagementPage.java @@ -189,6 +189,7 @@ public final class JavaManagementPage extends ListPageBase { JavaPageSkin(JavaManagementPage skinnable) { super(skinnable); + this.listView.getStyleClass().add("no-horizontal-scrollbar"); } @Override @@ -210,7 +211,7 @@ public final class JavaManagementPage extends ListPageBase { @Override protected ListCell createListCell(JFXListView listView) { - return new JavaItemCell(); + return new JavaItemCell(listView); } } @@ -222,7 +223,7 @@ public final class JavaManagementPage extends ListPageBase { private final StackPane removeIconPane; private final Tooltip removeTooltip = new Tooltip(); - JavaItemCell() { + JavaItemCell(JFXListView listView) { BorderPane root = new BorderPane(); HBox center = new HBox(); @@ -272,6 +273,8 @@ public final class JavaManagementPage extends ListPageBase { root.setPadding(new Insets(8)); this.graphic = new RipplerContainer(root); + + FXUtils.limitCellWidth(listView, this); } @Override diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java index 171fac320..676998138 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java @@ -558,11 +558,8 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP setPrefWidth(0); - if (listView.lookup(".clipped-container") instanceof Region clippedContainer) { - maxWidthProperty().bind(clippedContainer.widthProperty()); - prefWidthProperty().bind(clippedContainer.widthProperty()); - minWidthProperty().bind(clippedContainer.widthProperty()); - } + FXUtils.limitCellWidth(listView, this); + } @Override diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index 3076120ea..eb10eae33 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -955,6 +955,13 @@ -fx-background-color: transparent; } +.no-horizontal-scrollbar .scroll-bar:horizontal { + -fx-opacity: 0; + -fx-max-height: 0; + -fx-min-height: 0; + -fx-pref-height: 0; +} + .options-list { -fx-background-color: transparent; -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.26), 5, 0.06, -0.5, 1);