-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS Styling for JFoenix Autocomplete on ComboBox #890
Comments
Hi, ...
Scene scene = new Scene(root, 300, 275);
scene.getStylesheets().add(Main.class.getResource("/main-app.css").toExternalForm());
... In the CSS file you have to define the following: ...
/*Change selected cells of autocomplete popup*/
.jfx-autocomplete-popup .list-cell:filled:selected {
-fx-background-color: #64ffe6;
}
/*Change cells of autocomplete popup*/
.jfx-autocomplete-popup .list-cell {
-fx-background-color: #5f68ff;
}
/*Change cells of combobox*/
.combo-box .list-cell {
-fx-background-color: #ff92b8;
}
... .list-cell has also some other pseudo classes. That should produce the following: Greetings |
@schlegel11 those items set though, lol. Maybe I should use better naming in demos :p |
Don't worry 😉 |
@schlegel11 unfortunately it is not working at my end even after trying the CSS styling you have mentioned (Screenshot attached). I am using ComboBox not JFXComboBox, & trying the AutoComplete feature only as per the code referenced in my initial message (is it necessary to use JFxComboBox only to get the CSS styling working?) |
Hi, package sample;
import com.jfoenix.controls.JFXAutoCompletePopup;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Combo");
ComboBox<String> comboBox = new ComboBox<>();
Pane root = new Pane(comboBox);
comboBox.setEditable(true);
comboBox.getItems().addAll("HELLO", "TROLL", "WFEWEF", "WEF");
JFXAutoCompletePopup<String> autoCompletePopup = new JFXAutoCompletePopup<>();
autoCompletePopup.getSuggestions().addAll(comboBox.getItems());
// SelectionHandler sets the value of the comboBox
autoCompletePopup.setSelectionHandler(
event -> {
comboBox.setValue(event.getObject());
});
TextField editor = comboBox.getEditor();
editor
.textProperty()
.addListener(
observable -> {
// The filter method uses the Predicate to filter the Suggestions defined above
// I choose to use the contains method while ignoring cases
autoCompletePopup.filter(
item -> item.toLowerCase().contains(editor.getText().toLowerCase()));
// Hide the autocomplete popup if the filtered suggestions is empty or when the box's
// original popup is open
if (autoCompletePopup.getFilteredSuggestions().isEmpty()
|| comboBox.showingProperty().get()) {
autoCompletePopup.hide();
} else {
autoCompletePopup.show(editor);
}
});
Scene scene = new Scene(root, 300, 275);
scene.getStylesheets().add(Main.class.getResource("/main-app.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
} Where main-app.css is located in a resources dir. Greetings |
@schlegel11 a little perplexed. If I run just this sample code it works, but the same does not in my application. Is it something to do with JDK11 as I am using that. Also if I run this code using JDK11 I get an error as posted by someone here - Link So to test this code I had to switch the JDK to JDK10 & it worked. Also my view is maintained in a FXML file. Could JDK11 & FXML have any bearing on how JFoenix autocompletion CSS behaves ? |
Hmm ok. Greetings |
Thank you very much for your time. If I manage 2 find something will post it here or if JFoenix developers have a look at it & point out would help. Thanks once again. |
Is there a way to use CSS to style the drop down list background color of the Combo Box? I am using ComboBox (not JFXComboBox) & trying JFoenix Autocompletion, but the CSS styling not working.
I tried with below code as shown in #644 (comment)
.autocomplete-popup .autocomplete-list {
-fx-background-color: yellow;
}
Code used for AutoComplete as shown in #220 (comment)
Hope the issue faced is clear.
The text was updated successfully, but these errors were encountered: