From 739b2ccc0ed7061568cebd265f45e29704899a59 Mon Sep 17 00:00:00 2001 From: Glavo Date: Wed, 10 Dec 2025 20:37:54 +0800 Subject: [PATCH 1/3] update --- .../ui/construct/JFXCheckBoxTableCell.java | 68 +++++++++++++++++++ .../hmcl/ui/versions/ModUpdatesPage.java | 8 +-- 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java new file mode 100644 index 0000000000..735a7a1dda --- /dev/null +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java @@ -0,0 +1,68 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2025 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.ui.construct; + +import com.jfoenix.controls.JFXCheckBox; +import javafx.beans.binding.Bindings; +import javafx.beans.property.BooleanProperty; +import javafx.scene.control.TableCell; +import javafx.scene.control.TableColumn; +import javafx.util.Callback; + +/// @author Glavo +public final class JFXCheckBoxTableCell extends TableCell { + public static Callback, TableCell> forTableColumn( + final TableColumn column) { + return list -> new JFXCheckBoxTableCell<>(); + } + + private final JFXCheckBox checkBox = new JFXCheckBox(); + private BooleanProperty booleanProperty; + + public JFXCheckBoxTableCell() { + this.getStyleClass().add("jfx-checkbox-table-cell"); + } + + @Override + protected void updateItem(T item, boolean empty) { + super.updateItem(item, empty); + super.updateItem(item, empty); + + if (empty) { + setText(null); + setGraphic(null); + } else { + setGraphic(checkBox); + + if (booleanProperty != null) { + checkBox.selectedProperty().unbindBidirectional(booleanProperty); + } + if (getTableColumn().getCellObservableValue(getIndex()) instanceof BooleanProperty obsValue) { + booleanProperty = obsValue; + checkBox.selectedProperty().bindBidirectional(booleanProperty); + } + + checkBox.disableProperty().bind(Bindings.not( + getTableView().editableProperty().and( + getTableColumn().editableProperty()).and( + editableProperty()) + )); + } + } + +} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java index e3f253e169..5975dafc82 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java @@ -18,16 +18,15 @@ package org.jackhuang.hmcl.ui.versions; import com.jfoenix.controls.JFXButton; +import com.jfoenix.controls.JFXCheckBox; import javafx.beans.property.*; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.geometry.Pos; -import javafx.scene.control.CheckBox; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; -import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import org.jackhuang.hmcl.mod.LocalModFile; @@ -38,6 +37,7 @@ import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.ui.construct.JFXCheckBoxTableCell; import org.jackhuang.hmcl.ui.construct.MessageDialogPane; import org.jackhuang.hmcl.ui.construct.PageCloseEvent; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; @@ -72,9 +72,9 @@ public ModUpdatesPage(ModManager modManager, List update getStyleClass().add("gray-background"); TableColumn enabledColumn = new TableColumn<>(); - CheckBox allEnabledBox = new CheckBox(); + var allEnabledBox = new JFXCheckBox(); enabledColumn.setGraphic(allEnabledBox); - enabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(enabledColumn)); + enabledColumn.setCellFactory(JFXCheckBoxTableCell.forTableColumn(enabledColumn)); setupCellValueFactory(enabledColumn, ModUpdateObject::enabledProperty); enabledColumn.setEditable(true); enabledColumn.setMaxWidth(40); From 4950772c13296e9e7addcc59c007e4917a349876 Mon Sep 17 00:00:00 2001 From: Glavo Date: Wed, 10 Dec 2025 20:57:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=B0=86=20TableView=20=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=20CheckBox=20=E6=9B=BF=E6=8D=A2=E4=B8=BA=20JFXCheckBox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java | 1 + .../java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java | 1 + HMCL/src/main/resources/assets/css/root.css | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java index 735a7a1dda..9f79f28c07 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java @@ -46,6 +46,7 @@ protected void updateItem(T item, boolean empty) { if (empty) { setText(null); setGraphic(null); + checkBox.disableProperty().unbind(); } else { setGraphic(checkBox); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java index 5975dafc82..00be5bf699 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java @@ -73,6 +73,7 @@ public ModUpdatesPage(ModManager modManager, List update TableColumn enabledColumn = new TableColumn<>(); var allEnabledBox = new JFXCheckBox(); + enabledColumn.setStyle("-fx-alignment: CENTER;"); enabledColumn.setGraphic(allEnabledBox); enabledColumn.setCellFactory(JFXCheckBoxTableCell.forTableColumn(enabledColumn)); setupCellValueFactory(enabledColumn, ModUpdateObject::enabledProperty); diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index 7d7c06e7d1..2bb6cf1731 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -813,6 +813,10 @@ -jfx-unchecked-color: transparent; } +.table-view .jfx-check-box .jfx-rippler { + -jfx-rippler-disabled: true; +} + /******************************************************************************* * * * JFX Progress Bar * From 6c489f2f8c64a7d127ab309018ef0fd03d0387f9 Mon Sep 17 00:00:00 2001 From: Glavo Date: Thu, 11 Dec 2025 20:38:26 +0800 Subject: [PATCH 3/3] update --- .../org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java | 1 - 1 file changed, 1 deletion(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java index 9f79f28c07..8473c6e7e3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java @@ -41,7 +41,6 @@ public JFXCheckBoxTableCell() { @Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); - super.updateItem(item, empty); if (empty) { setText(null);