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.bindAutoCompletion(txt_numberOfCard_GENERAL, cardNumber);
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<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);
I had a similar problem using TextFields.bindAutoCompletion
I wanted the autocompletion to be the same size as the text field. After some research, I found that the bindAutoCompletion method returns a AutoCompletionBinding object. With this object I did just that to keep with the same size:
AutoCompletionBinding<Unidade> autoComplete = TextFields.bindAutoCompletion(this.txtField,units);
autoComplete.prefWidthProperty().bind(this.txtField.widthProperty());
If you need to style the object, you can grab the AutoComplete Object and them add classes or even style it directly:
AutoCompletePopup<Unidade> autoCompletionPopup = autoComplete.getAutoCompletionPopup();
autoCompletionPopup.setStyle("-fx-font-weight: BOLD; -fx-font-size: 23; -fx-background-color: #EDECEC;");
// or with the following class: .itemMenu { -fx-font-weight: BOLD; }
// you can clear default styles too
//autoCompletionPopup.getStyleClass().clear();
autoCompletionPopup.getStyleClass().add("itemMenu");
i just little modify Antonio Lucas's Answer because some styling shows me "lication Thread"
Following are my code
AutoCompletePopup autoCompletionPopup = autoComplete.getAutoCompletionPopup();
autoCompletionPopup.setStyle("-fx-font:18px 'arial'");
Related
enter image description here
I am new to CSS and I am trying to get rid of the white space (as seen in the image) in the drop menu of the combo box... setting the background black didn't work... this is my CSS for the combo box
.combo-box {
-fx-border-width : 1 ;
-fx-border-color : #29a8a6;
-fx-text-fill: #29a8a6;
-fx-border-radius: 50;
-fx-padding : 0;
-fx-background-color: #29a8a6;
-fx-background-radius: 50;
}
.combo-box .list-cell{
-fx-prompt-text-fill : #29a8a6;
-fx-text-fill: #29a8a6;
-fx-background-color: black;
-fx-padding : 2;
-fx-cell-border : 0;
-fx-border-width: 0;
-fx-border-radius: 50;
-fx-background-radius: 50;
}
To get rid of the white space in the drop down menu you can add this to your css file:
.combo-box .list-view {
-fx-background-color: black;
}
PS:
Whenever you are not sure which elements styling you need to change, you can make use of Scenic View to find out the element.
apparently the problem was the listview in the combo-box , so setting the insets to 0 solved my problem
.combo-box {
-fx-background-color:#29a8a6;
-fx-background-radius : 40;
}
.combo-box .list-view {
-fx-prompt-text-fill : #29a8a6;
-fx-background-color : black;
-fx-background-radius : 40;
-fx-insets : 0;
}
.combo-box .list-cell{
-fx-prompt-text-fill : #29a8a6;
-fx-text-alignment : CENTER;
-fx-background-radius : 40;
-fx-background-color : black;
}
Context: Using SceneBuilder to build a Tabbed Pane application
Issue: I notice the visualization as seen in Scene Builder - Preview option & that when viewed after executing the program look different.
Note:
I am using the standard Tab & TabPane option available in Scene builder.
I use Scenebuilder 10.0.0 (executable Jar) & Java JDK 10
I have not applied any CSS styling, but even those suggested in the 2 links below did not help
Expectation: The output after program execution is the same as that observed in SceneBuilder-preview option.
I referred to Link1 & Link2 but dint help.
Scene Builder Output:
Program Execution Output :
Your application looks different from SceneBuilder preview because you're not using the same user-agent stylesheet theme.
JavaFx application uses its Modena theme by default, while you set SceneBuilder to use Gluon Mobile Light theme for design/preview (main menu: Preview -> Theme).
JavaFx doesn't come with Gluon Mobile Light theme, and if you want to use it, you need to setup your project to use Gluon Mobile SDK/library (Gluon Mobile).
The other option is to write custom css:
//custom-theme.css
.tab-pane > .tab-header-area {
-fx-padding: 0;
}
.tab-pane > .tab-header-area > .tab-header-background {
-fx-background-color: #E1E1E1, white;
-fx-background-insets: 0, 0 0 1px 0;
}
.tab-pane > .tab-header-area > .headers-region > .tab {
-fx-background-color: white;
-fx-background-insets: 0 0 1px 0;
-fx-padding: 1.5em 1em;
}
.tab-pane > .tab-header-area > .headers-region > .tab >.tab-container >.tab-label {
-fx-text-fill: #63B5F6;
}
.tab-pane > .tab-header-area > .headers-region > .tab:selected {
-fx-background-color: #2092ED, white;
-fx-background-insets: 0, 0 0 2px 0;
}
.tab-pane > .tab-header-area > .headers-region > .tab:selected >.tab-container >.tab-label {
-fx-text-fill: #2095F3;
}
.tab-pane > .tab-header-area > .headers-region > .tab:selected >.tab-container >.focus-indicator {
-fx-opacity: 0;
}
add the file to your project (put it in "src/main/resources" or somewhere else in classpath) and apply it to your application:
scene.getStylesheets().add("custom-theme.css");
This is how it looks
I customized porgressbar using css but when i used -fx-pref-width for .bar it did not work.This is my css :
.super-fx-progress-bar {
-fx-background-color: transparent;
}
.super-fx-progress-bar .track{
-fx-background-color: transparent;
-fx-border-radius:20;
-fx-background-radius:20;
}
.super-fx-progress-bar .bar {
-fx-background-color: #0057e7,transparent,#6666ff;
-fx-background-insets: 1 1 1 3, 1 1 1 1, 1 1 2 3;
-fx-border-radius:20;
-fx-background-radius:20;
-fx-pref-width:2
/*What should i add to minimize width of bar when its value is indeterminated*/
}
You can do this by adding :
-fx-indeterminate-bar-length:value;
in progressbar class (you used .super-fx-progress-bar) :
I did this to show the differents results :
First style :
.super-fx-progress-bar {
-fx-background-color: transparent;
-fx-indeterminate-bar-animation-time:1.0;
-fx-indeterminate-bar-flip:true;
-fx-indeterminate-bar-escape:true;
-fx-indeterminate-bar-length:20;
-fx-min-height:5;
}
Second style :
.super-fx-progress-bar {
-fx-background-color: transparent;
-fx-indeterminate-bar-animation-time:1.0;
-fx-indeterminate-bar-flip:true;
-fx-indeterminate-bar-escape:true;
-fx-indeterminate-bar-length:60;
-fx-min-height:5;
}
I have problem with styling ComboBox in css. I don't know how to change font color of selected item fx (2 people from black color to red), and how to set color effect when you point mouse on the current choice.
css code:
.combo-box
{
-fx-background-image:url("people_button.jpg");
-fx-text-fill: red;
-fx-min-width: 128;
-fx-min-height: 48;
}
.combo-box-popup .list-view
{
-fx-background-color: -fx-box-border, -fx-control-inner-background;
-fx-background-insets: 0, 1;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 8, 0.0 , 0 , 0 );
}
.combo-box-popup .list-view .list-cell
{
-fx-background-color: #ececec;
-fx-text-fill: #9a9a9a;
-fx-font-family: Oxygen Light;
}
and java code:
ComboBox<String> combo = new ComboBox();
combo.setVisibleRowCount(5);
combo.setItems(observableList);
combo.setValue("1 person");
Just add the pseudo-class hover to your style sheet :
.combo-box-popup .list-view .list-cell:hover {
-fx-text-fill: red;
}
For adding a color to the selected item, use the pseudo-class selected :
.combo-box .cell:selected {
-fx-text-fill: red;
}
Is there a simple way to hide the calendar button on the DatePicker Node in JavaFX? Some of our dates are not editable, and the calendar button is just adding to the width of the field.
You can use the following css to remove the calendar button
.date-picker > .arrow-button {
-fx-padding: 0px;
}
.date-picker > .arrow-button > .arrow {
-fx-padding: 0px;
}
Edit - To get back the right border :
.date-picker > .date-picker-display-node {
-fx-background-insets: 1 1 1 1;
}
Edit - To apply the above style to only few datepickers
Declare a DatePicker and add a styleclass to it.
DatePicker nonEditableDatePicker = new DatePicker();
nonEditableDatePicker.getStyleClass().add("non-editable-datepicker");
Use this styleclass to add styles :
.non-editable-datepicker > .arrow-button {
-fx-padding: 0px;
}
.non-editable-datepicker > .arrow-button > .arrow {
-fx-padding: 0px;
}
.non-editable-datepicker > .date-picker-display-node {
-fx-background-insets: 1 1 1 1;
}