在JavaFX中更改ListView字体大小 [英] Change ListView font size in JavaFX

查看:410
本文介绍了在JavaFX中更改ListView字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to know how can I change the list view items text font size in JavaFx. The size of each row text will vary . I tried using cell factor property but i don't know how to use it. Can anybody help me here ?

推荐答案


类似的问题在这里:

A similar question is here:

如何在JavaFX中更改ListView中的字体大小?

您还可以使用 .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;
}




如何在JavaFX中使用外部css?

How to use external css in JavaFX?

如何使用外部css文件为javafx应用程序设置样式


如何以编程方式更改文本的大小?:

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));
                    }
                }
            };
        });

这篇关于在JavaFX中更改ListView字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆