How can i change bar width of progressbar? - css

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

Related

Trying to get rid of the white border in the ComboBox

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

JavaFX tableview with CSS scrolling issue

I am currently facing a problem with javafx table. I have a tableview that shows a list of subjects. The background color of each row depends if a subject is able to be enrolled or not. Subjects with green background can be enrolled and subjects with pink background cannot be enrolled. The problem occurs when scrolling the table.
TableView before scrolling
TableView after scrolling down and up
After scrolling, the background color of rows have changed and the subjects with green background might become pink and vice versa. This works perfectly without adding a css to the table.
Code I used to set the background color of rows
tblAvailableSubjects.setRowFactory((TableView<Subject> param) -> {
TableRow<Subject> row = new TableRow<>();
row.emptyProperty().addListener((obs, wasEmpty, isEmpty) -> {
if(isEmpty) {
row.setContextMenu(null);
row.setStyle("-fx-border-color: transparent");
} else {
Subject subject = row.getItem();
if(subject.getSubjectEvaluation().equals(SubjectEvaluation.COMPLETED)) {
row.setStyle("-fx-background: #B2EBF2");
} else if(subject.getSubjectEvaluation().equals(SubjectEvaluation.FAILED)) {
row.setStyle("-fx-background: #FF0000");
row.setContextMenu(tblAvailableContext);
} else if(subject.getSubjectEvaluation().equals(SubjectEvaluation.OKAY)) {
row.setStyle("-fx-background: #8BC34A");
row.setContextMenu(tblAvailableContext);
} else if(subject.getSubjectEvaluation().equals(SubjectEvaluation.ENROLLWITHCOREQ)) {
row.setStyle("-fx-background: #FFEB3B");
row.setContextMenu(tblAvailableContext);
} else if(subject.getSubjectEvaluation().equals(SubjectEvaluation.CANTENROLL)) {
row.setStyle("-fx-background: #FFCDD2");
}
}
});
return row;
});
CSS for table
.table-view {
/* Constants used throughout the tableview. */
-fx-table-header-border-color: transparent;
-fx-table-cell-border-color: -fx-box-border;
/* Horizontal Lines*/
-fx-background-color: transparent;
}
.table-view .filler, .table-view .column-header
{
-fx-size: 40;
-fx-border-style: null;
-fx-border-color: rgb(200.0, 200.0, 200.0);
-fx-border-width: 0 0 1 0;
-fx-background-color: transparent;
}
.table-view .show-hide-columns-button
{
-fx-background-color: transparent;
}
.table-view .column-header .label,
.table-view .column-drag-header .label
{
-fx-alignment: CENTER_LEFT;
}
.table-view .column-header-background
{
-fx-background-color: transparent;
}
.table-row-cell {
-fx-cell-size: 30px;
}
.table-cell {
-fx-border-color: transparent;
-fx-border-width: 1;
}
EDIT: The subject's SubjectEvaluation value doesn't change, it seems that it switches the context menu and background color between rows when scrolling.
I hope someone could help me with this. Thanks.

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

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'");

JavaFX : Style combobox popup list text color and selected item color?

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

Hide Calendar Button on DatePicker?

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

Resources