javafx – 如何更改自动完成TextField(ControlFX)的样式?
发布时间:2020-12-15 02:18:36 所属栏目:Java 来源:网络整理
导读:我有一个来自controlsFX的Autocomplete TextField,我想改变每个项目的大小和颜色. 这是我的代码部分: TextFields.bindAutoCompletion(txt_numberOfCard_GENERAL,cardNumber); 解决方法 编辑: ControlFX的自动完成是一个包含ListView的弹出窗口,AutoComplet
我有一个来自controlsFX的Autocomplete TextField,我想改变每个项目的大小和颜色.
这是我的代码部分: TextFields.bindAutoCompletion(txt_numberOfCard_GENERAL,cardNumber); 解决方法
编辑:
ControlFX的自动完成是一个包含ListView的弹出窗口,AutoComplete的默认值为css style: /** * 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%),-30%) ),-fx-control-inner; -fx-background-insets: -1 -2 -1 -1,0 -1 0 0; -fx-effect: dropshadow( gaussian,rgba(0,0.2),12,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代码中的样式,如下所示: 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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |