ListView控件样式选定的项目文本填充 - JavaFX的8魔法或者BUG? [英] ListView styling a selected item text-fill - JavaFX 8 MAGIC or BUG?

查看:950
本文介绍了ListView控件样式选定的项目文本填充 - JavaFX的8魔法或者BUG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到这问题并得到回答这个code:

I read this question and get this code from answer:

.list-cell:filled:selected:focused, .list-cell:filled:selected {
    /* 3:, 4: */
    -fx-background-color: linear-gradient(#333 0%, #777 25%, #aaa 75%, #eee 100%);
    -fx-text-fill: white; /* 5 */
}
.list-cell { -fx-text-fill: black; /* 5 */ }
.list-cell:odd { -fx-background-color: white; /* 1 */ }
.list-cell:even { -fx-background-color: #8f8; /* for information */ }
.list-cell:filled:hover { 
    -fx-background-color: #00f; /* 2 */
    -fx-text-fill: white; /* 5 */
}

我会做用黑色文本的填充(文本颜色)选择的项目。因此,我把这些类结果
  .LIST细胞:填充:选择:专注,.LIST细胞:填充:选择结果
和改变属性 -fx文本填充白色黑色,但没有任何反应,但如果我更改背景颜色为红色,则背景颜色发生了变化(这并不适用于文本颜色,这只是检查右班)

I would make the selected item with black text-fill (text-color). Therefore I take these classes
.list-cell:filled:selected:focused, .list-cell:filled:selected
and change attribute -fx-text-fill from white to black, but nothing happens, but if I change background color to red, then background color have changed (this does not apply to text color, this is just check on right classes)

如何更改所选项目的文本颜色集中的ListView?

How to change text color of selected item in focused ListView?

UPD1:结果
我试图改变列表的单元格中的文本颜色只是这种变异:

UPD1:
I tried to change text color of list-cell just in this variant:

.list-cell{
    -fx-text-fill: magenta;
}

和这个变种:

.list-view:focused > .virtual-flow > .clipped-container > .sheet > .list-cell:filled{
    -fx-text-fill: magenta;
}

但没有任何工程

推荐答案

我尝试以下code和它工作得很好爪哇8.改变选中单元格的文本颜色。

I tried the following code and it works just fine on Java 8. It changes the text color of the selected cell.

ListViewSample.java

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class ListViewSample extends Application {

    ListView<String> list = new ListView<String>();
    ObservableList<String> data = FXCollections.observableArrayList(
            "chocolate", "salmon", "gold", "coral", "darkorchid",
            "darkgoldenrod", "lightsalmon", "black", "rosybrown", "blue",
            "blueviolet", "brown");
    final Label label = new Label();

    @Override
    public void start(Stage stage) {
        VBox box = new VBox();
        Scene scene = new Scene(box, 200, 200);
        scene.getStylesheets().add(this.getClass().getResource("list.css").toExternalForm());
        stage.setScene(scene);
        stage.setTitle("ListViewSample");
        box.getChildren().addAll(list, label);
        VBox.setVgrow(list, Priority.ALWAYS);

        label.setLayoutX(10);
        label.setLayoutY(115);
        label.setFont(Font.font("Verdana", 20));
        list.setItems(data);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

list.css

.list-cell:filled:selected {
    -fx-text-fill: red;
}

这也可以工作:

.list-cell:filled:selected:focused, .list-cell:filled:selected {
    -fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%);
    -fx-text-fill: red;
}

这篇关于ListView控件样式选定的项目文本填充 - JavaFX的8魔法或者BUG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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