diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java index 5061a7c9e..8b35d9eb7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java @@ -30,20 +30,11 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.fxml.FXML; import javafx.scene.control.Label; -import javafx.scene.control.ScrollPane; import javafx.scene.control.ToggleGroup; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.Pane; -import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.text.Font; -import javafx.scene.text.Text; import org.jackhuang.hmcl.setting.*; -import org.jackhuang.hmcl.task.Task; -import org.jackhuang.hmcl.ui.construct.FontComboBox; -import org.jackhuang.hmcl.ui.construct.MultiFileItem; import org.jackhuang.hmcl.ui.construct.Validator; import org.jackhuang.hmcl.ui.wizard.DecoratorPage; import org.jackhuang.hmcl.upgrade.UpdateChannel; @@ -75,7 +66,7 @@ public final class SettingsPage extends SettingsView implements DecoratorPage { cboDownloadSource.getSelectionModel().select(DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(Settings.instance().getDownloadProvider())); cboDownloadSource.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> Settings.instance().setDownloadProvider(DownloadProviders.getDownloadProvider(newValue.intValue()))); - cboFont.getSelectionModel().select(Settings.instance().getFont().getFamily()); + cboFont.initValue(Settings.instance().getFont()); cboFont.valueProperty().addListener((a, b, newValue) -> { Font font = Font.font(newValue, Settings.instance().getFont().getSize()); Settings.instance().setFont(font); 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 9af52cff5..aab8ce69c 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 @@ -24,11 +24,10 @@ import javafx.scene.control.ListCell; import javafx.scene.text.Font; public class FontComboBox extends JFXComboBox { + private boolean loaded = false; public FontComboBox(@NamedArg(value = "fontSize", defaultValue = "12.0") double fontSize, @NamedArg(value = "enableStyle", defaultValue = "false") boolean enableStyle) { - super(FXCollections.observableArrayList(Font.getFamilies())); - valueProperty().addListener((a, b, newValue) -> { if (enableStyle) setStyle("-fx-font-family: \"" + newValue + "\";"); @@ -44,5 +43,15 @@ public class FontComboBox extends JFXComboBox { } } }); + + setOnMouseClicked(e -> { + if (loaded) return; + getItems().setAll(Font.getFamilies()); + }); + } + + public void initValue(Font font) { + getItems().setAll(font.getFamily()); + getSelectionModel().select(font.getFamily()); } }