Hide Calendar Button on DatePicker? - javafx

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

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 Tab - Appearance differs from SceneBuilder

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

JavaFX how to hide empty column cell in tableView

I am using a tableView with UNCONSTRAINED_RESIZE_POLICY.
And I want set all empty column cell to white background.
This is the current view.
I am trying to search the empty node, but I can't find it even if I search all the nodes contained in tableView by following code (test function):
private void test() {
ArrayList<Node> nodes = getAllNodes(tableView);
nodes.forEach(node -> {
if(node instanceof TableCell) {
if(((TableCell) node).getText() == null || ((TableCell) node).getText().isEmpty()) {
System.out.println(true);
}
}
});
}
public static ArrayList<Node> getAllNodes(Parent root) {
ArrayList<Node> nodes = new ArrayList<Node>();
addAllDescendents(root, nodes);
return nodes;
}
private static void addAllDescendents(Parent parent, ArrayList<Node> nodes) {
for (Node node : parent.getChildrenUnmodifiable()) {
nodes.add(node);
if (node instanceof Parent)
addAllDescendents((Parent)node, nodes);
}
}
Use a CSS stylesheet to apply the styles to remove the background from TableRowCells and instead add the background to the TableCells:
/* overwrite default row style */
.table-row-cell {
-fx-background-color: transparent;
-fx-background-insets: 0;
}
/* apply row style to cells instead */
.table-row-cell .table-cell {
-fx-background-color: -fx-table-cell-border-color, -fx-background;
-fx-background-insets: 0, 0 0 1 0;
}
.table-row-cell:odd {
-fx-background: -fx-control-inner-background-alt;
}
/* fix markup for selected cells/cells in a selected row */
.table-row-cell:filled > .table-cell:selected,
.table-row-cell:filled:selected > .table-cell {
-fx-background: -fx-selection-bar-non-focused;
-fx-table-cell-border-color: derive(-fx-background, 20%);
}
.table-view:focused > .virtual-flow > .clipped-container > .sheet > .table-row-cell:filled:selected .table-cell,
.table-view:focused > .virtual-flow > .clipped-container > .sheet > .table-row-cell .table-cell:selected {
-fx-background: -fx-selection-bar;
}
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
Note: There are no TableCells outside of existing columns. The background is applied to the TableRowCells.
Also retrieving the cells from a virtualizing control is a bad idea:
The cells are created during the first layout pass. They may not be present at the time you run your code.
Interacting with the control (e.g. by resizing it, scrolling it, ect.) may result in creation of additional cells. Any modifications you've done to the cells you found before by traversing the scene are not applied to those new nodes automatically.
The easiest way is:
.table-row-cell:empty {
-fx-background-color: transparent;
}

How can i change bar width of progressbar?

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

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

Resources