How do I change the style of Autocomplete TextField (ControlFX)?

前端 未结 1 844
春和景丽
春和景丽 2021-01-14 00:28

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

This is my part of code :

TextFields.bindA         


        
1条回答
  •  迷失自我
    2021-01-14 01:15

    Edit :

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

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

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

    0 讨论(0)
提交回复
热议问题