如何更改自动完成TextField

如何更改自动完成TextField

本文介绍了如何更改自动完成TextField(ControlFX)的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有来自controlsFX的Autocomplete TextField,我想更改每个项目的大小和颜色。

I have an Autocomplete TextField from controlsFX and I want to change the size and the color of each item.

这是我的代码部分:

TextFields.bindAutoCompletion(txt_numberOfCard_GENERAL, cardNumber);

推荐答案

修改:

ControlFX 自动完成是一个包含ListView的弹出窗口,默认是:

Autocomplete from ControlFX is a Popup window contains ListView ,the default css style of AutoComplete is :

/**
 * Style based on Modena.css combo-box-popup style
 */

.auto-complete-popup > .list-view {
    -fx-background-color:
        linear-gradient(to bottom,
        derive(-fx-color,-17%),
        derive(-fx-color,-30%)
        ),
        -fx-control-inner;
    -fx-background-insets: -1 -2 -1 -1, 0 -1 0 0;
    -fx-effect: dropshadow( gaussian , rgba(0,0,0,0.2) , 12, 0.0 , 0 , 8 );
}
.auto-complete-popup > .list-view > .virtual-flow > .clipped-container > .sheet > .list-cell {
    -fx-padding: 4 0 4 5;
    /* No alternate highlighting */
    -fx-background: -fx-control-inner-background;
}
.auto-complete-popup > .list-view > .virtual-flow > .clipped-container > .sheet > .list-cell:filled:selected {
    -fx-background:  -fx-selection-bar-non-focused;
    -fx-background-color:  -fx-background;
}
.auto-complete-popup  > .list-view > .virtual-flow > .clipped-container > .sheet > .list-cell:filled:hover,
.auto-complete-popup  > .list-view > .virtual-flow > .clipped-container > .sheet > .list-cell:filled:selected:hover {
    -fx-background: -fx-accent;
    -fx-background-color: -fx-selection-bar;
}
.auto-complete-popup > .list-view > .placeholder > .label {
    -fx-text-fill: derive(-fx-control-inner-background,-30%);
}

因此您需要在样式表文件中覆盖此类,或者更改来自您的Java代码的样式如下:

So you need to override this class in your Stylesheet file,or by changing the style from your java code like this :

        AutoCompletePopup<String> autoCompletePopup = new AutoCompletePopup<>();
        autoCompletePopup.getSuggestions().addAll("Fruit", "Fruits", "Frites", "Cheese!");
        autoCompletePopup.setStyle("-fx-control-inner-background:WHITE;"
                + "-fx-accent: #E8EAF6;"
                + "-fx-selection-bar-non-focused:red;"
                + "-fx-font:18px 'Arial'");
            autoCompletePopup.show(textField);

这篇关于如何更改自动完成TextField(ControlFX)的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:34