JavaFX中的ListView样式 [英] ListView styling in JavaFX

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

问题描述

我有一个列表视图。我想更改背景颜色和文本填充。我尝试过以下操作:

I have a listview. I want to change the color of the background and the text fill. I have tried doing the following:

playlistView.setStyle("-fx-background-color: blue; -fx-text-fill: black;");

但是,这不起作用。但是,以下工作正常:

But, this doesn't work. However, the following is working:

playlistView.setStyle("-fx-font-size: 24px; -fx-font-family: 'SketchFlow Print';");

你能告诉我如何让背景和文本填充起作用吗?谢谢。

Can you please tell me how to get the background and text-fill to work? Thank you.

推荐答案

您可以使用以下CSS样式:

You can use the following CSS styles:

.list-view .list-cell:even {
-fx-background-color: blue;
-fx-text-fill: black;
}
.list-view .list-cell:odd {
-fx-background-color: blue;
-fx-text-fill: black;
}




  1. 将此样式的内容保存在 lisStyles.css

  2. 添加 lisStyles.css 样式表到场景:

scene.getStylesheets()。add(getClass()。getResource(lisStyles.css)。toExternalForm ());

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

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