java - 在 JavaFX 中更改 ListView 字体大小

标签 java javafx

我想知道如何更改 JavaFx 中的 ListView 项文本字体大小。每行文本的大小会有所不同。我尝试使用细胞因子属性,但我不知道如何使用它。有人可以帮我吗?

最佳答案

A similar question is here:

How to change the font size in ListView in JavaFX?

您也可以使用下面的 .css:

.list-cell:filled:selected:focused, .list-cell:filled:selected {
    -fx-background-color: linear-gradient(#328BDB 0.0%, #207BCF 25.0%, #1973C9 75.0%, #0A65BF 100.0%);
    -fx-text-fill: white;
}

.list-cell{
    -fx-font-size:15.0;
}

.list-cell:even { /* <=== changed to even */
    -fx-background-color: white;
}

.list-cell:filled:hover {
    -fx-background-color: #0093ff;
    -fx-text-fill: white;
}

How to use external css in JavaFX?

How to use external css file to style a javafx application

How to programmatically change the size of text?:

Java8之前:

listView.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
            @Override
            public ListCell<String> call(ListView<String> p) {
                return new ListCell<String>() {
                    @Override
                    protected void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);
                        if (item != null) {
                            setText(item);

                            // decide to add a new styleClass
                            // getStyleClass().add("costume style");
                            // decide the new font size
                            setFont(Font.font(16));
                        }
                    }
                };
            }
        });

使用 lambda 表达式:

listView.setCellFactory(cell -> {
            return new ListCell<String>() {
                @Override
                protected void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        setText(item);

                        // decide to add a new styleClass
                        // getStyleClass().add("costume style");
                        // decide the new font size
                        setFont(Font.font(16));
                    }
                }
            };
        });

关于java - 在 JavaFX 中更改 ListView 字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39620548/

相关文章:

java - 陷入语法困境,将对象内置到数组中

java - 从 JavaFX 获取用户输入

css - 在路径中加载带有空格的 JavaFX CSS

java - 使用 List 填充 ListView

java - 如何通过更改标题(即旋转对象)来避免与边框或彼此之间的碰撞

JavaFX 正在运行,但 try-catch-finally 代码不起作用

listview - JavaFX ListView - 通过鼠标单击将项目添加到选择中

java - java中如何将这个curl请求转换为Http post请求进行文件上传?

java - 在 Linux 中增加 java 堆空间

java - 查找包含给定字符串的所有组合的最短文本