|
19 | 19 |
|
20 | 20 | import javafx.beans.InvalidationListener; |
21 | 21 | import javafx.beans.binding.Bindings; |
| 22 | +import javafx.beans.binding.DoubleBinding; |
22 | 23 | import javafx.beans.property.StringProperty; |
23 | 24 | import javafx.beans.property.StringPropertyBase; |
24 | 25 | import javafx.collections.FXCollections; |
|
30 | 31 | import javafx.scene.layout.HBox; |
31 | 32 | import javafx.scene.layout.Priority; |
32 | 33 | import javafx.scene.layout.VBox; |
33 | | -import org.jackhuang.hmcl.ui.FXUtils; |
34 | 34 |
|
35 | 35 | public class TwoLineListItem extends VBox { |
36 | 36 | private static final String DEFAULT_STYLE_CLASS = "two-line-list-item"; |
@@ -177,7 +177,14 @@ public ObservableList<Label> getTags() { |
177 | 177 | lblTitle.setMinWidth(Label.USE_PREF_SIZE); |
178 | 178 | scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); |
179 | 179 | scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); |
180 | | - FXUtils.onChangeAndOperate(tagsBox.heightProperty(), height -> FXUtils.setLimitHeight(scrollPane, height.doubleValue())); |
| 180 | + DoubleBinding expectedHeight = Bindings.createDoubleBinding( |
| 181 | + () -> tags.isEmpty() ? 0.0 : tagsBox.prefHeight(-1), |
| 182 | + tags |
| 183 | + ); |
| 184 | + |
| 185 | + scrollPane.minHeightProperty().bind(expectedHeight); |
| 186 | + scrollPane.prefHeightProperty().bind(expectedHeight); |
| 187 | + scrollPane.maxHeightProperty().bind(expectedHeight); |
181 | 188 | firstLine.getChildren().setAll(lblTitle, scrollPane); |
182 | 189 |
|
183 | 190 | tags.addListener((InvalidationListener) ignored -> scrollPane.requestLayout()); |
|
0 commit comments