On reference to RT-28447. I'll trying again the code below and it doesn`t work. I'm trying to insert an image on LisCell and change the Style and doesn´t work again.
I'll be waiting your answer, thanks.
Here is the code test.
package combobox.test;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Callback;
public class CBTest extends Application {
private AnchorPane root = new AnchorPane();
public void start(Stage primaryStage) {
root.setPrefSize(200, 200);
root.setStyle("-fx-background-color:#ffffff;");
ObservableList<String> list = FXCollections.observableArrayList("First","Second","Third","Fourth","Fifth");
ComboBox<String> comboBox = new ComboBox<String>(list);
comboBox.setId("my-combo");
comboBox.getStyleClass().add("my-combo");
comboBox.getSelectionModel().selectFirst();
comboBox.setLayoutX(50);
comboBox.setLayoutY(50);
comboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
@Override
public ListCell<String> call(ListView<String> p) {
p.setPrefHeight(130);
p.setPrefWidth(110);
//Not change text-fill && not add image
p.setStyle("-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E); " +
"-fx-border-width:1 1 1 1; -fx-border-color:#C4D019; " +
"-fx-border-radius: 5 5 5 5; -fx-background-radius:5 5 5 5; " +
"-fx-font-family:Time ; -fx-font-size:14px; -fx-text-fill: #035bf1;" +
"-fx-graphic:url('imgcab_cmbperfil.png');");
return new ListCell<String>() {
{
setStyle("-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E); " +
"-fx-border-width:1px 0px 0px 0px; -fx-border-color:#9E9E9E;" +
"-fx-font-family:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;" +
"-fx-graphic:url('imgcab_cmbperfil.png');");
setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
if (!isSelected())
setStyle("-fx-background-color: linear-gradient(to bottom,#C4D019, #586f25); " +
"-fx-font-family:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;");
}
});
setOnMouseExited(new EventHandler<MouseEvent>() {
public void handle(MouseEvent mouseEvent) {
if (!isSelected())
setStyle("-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E); " +
"-fx-font-family:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;");
}
});
}
@Override
public void updateSelected(boolean selected)
{
if (selected)
{
setStyle("-fx-background-color: linear-gradient(to bottom,#C4D019, #586F25); -fx-graphic:url('imgcab_cmbperfil.png'); " +
"-fx-graphic-text-gap:10;");
}
else
{
setStyle("-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E); -fx-label-padding:0px 0px 0px 0px;" +
"-fx-font-family:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;");
}
super.updateSelected(selected);
}
@Override
protected void updateItem(String item, boolean empty)
{
super.updateItem(item, empty);
setText(item);
}
};
}
});
root.getChildren().add(comboBox);
System.out.println("Creo el combobox");
Scene scene = new Scene(root);
String cssURL = getClass().getResource("combo-box.css").toExternalForm();
scene.getStylesheets().add(cssURL);
System.out.println("Creo scene");
primaryStage.setScene(scene);
primaryStage.show();
System.out.println("Creo el combobox");
}
public static void main(String[] args) {
launch(args);
}
}
.css file
.tool-bar:horizontal {
-fx-background-color: #b3e6b3
}
#my-combo{
-fx-background-color: linear-gradient(to bottom,#5C5C5C, #1C1C1C);
-fx-border-color: #FFFFFF;
-fx-border-width: 1 1 1 1;
-fx-border-radius: 5 5 5 5;
-fx-padding:0 0 0 10;
}
#my-combo:hover{
-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E);
-fx-border-color:#C4D019;
}
#my-combo .arrow-button{
-fx-background-color: linear-gradient(to bottom,#5C5C5C, #1C1C1C);
-fx-padding:11 10 10 10;
-fx-background-radius: 5 5 5 5;
-fx-border-width:0 0 0 1;
-fx-border-color:#222323;
}
#my-combo .arrow-button:hover{
-fx-background-color: linear-gradient(to bottom,#C4D019, #586F25);
}
#my-combo .arrow-button .arrow{
-fx-background-color: #FFFFFF;
}
/*#my-combo .list-cell {
-fx-font-family:Arial;
-fx-font-size: 14px;
-fx-text-fill: #FFFFFF;
-fx-background-color:darksalmon;
}*/
I'll be waiting your answer, thanks.
Here is the code test.
package combobox.test;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Callback;
public class CBTest extends Application {
private AnchorPane root = new AnchorPane();
public void start(Stage primaryStage) {
root.setPrefSize(200, 200);
root.setStyle("-fx-background-color:#ffffff;");
ObservableList<String> list = FXCollections.observableArrayList("First","Second","Third","Fourth","Fifth");
ComboBox<String> comboBox = new ComboBox<String>(list);
comboBox.setId("my-combo");
comboBox.getStyleClass().add("my-combo");
comboBox.getSelectionModel().selectFirst();
comboBox.setLayoutX(50);
comboBox.setLayoutY(50);
comboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
@Override
public ListCell<String> call(ListView<String> p) {
p.setPrefHeight(130);
p.setPrefWidth(110);
//Not change text-fill && not add image
p.setStyle("-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E); " +
"-fx-border-width:1 1 1 1; -fx-border-color:#C4D019; " +
"-fx-border-radius: 5 5 5 5; -fx-background-radius:5 5 5 5; " +
"-fx-font-family:Time ; -fx-font-size:14px; -fx-text-fill: #035bf1;" +
"-fx-graphic:url('imgcab_cmbperfil.png');");
return new ListCell<String>() {
{
setStyle("-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E); " +
"-fx-border-width:1px 0px 0px 0px; -fx-border-color:#9E9E9E;" +
"-fx-font-family:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;" +
"-fx-graphic:url('imgcab_cmbperfil.png');");
setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
if (!isSelected())
setStyle("-fx-background-color: linear-gradient(to bottom,#C4D019, #586f25); " +
"-fx-font-family:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;");
}
});
setOnMouseExited(new EventHandler<MouseEvent>() {
public void handle(MouseEvent mouseEvent) {
if (!isSelected())
setStyle("-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E); " +
"-fx-font-family:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;");
}
});
}
@Override
public void updateSelected(boolean selected)
{
if (selected)
{
setStyle("-fx-background-color: linear-gradient(to bottom,#C4D019, #586F25); -fx-graphic:url('imgcab_cmbperfil.png'); " +
"-fx-graphic-text-gap:10;");
}
else
{
setStyle("-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E); -fx-label-padding:0px 0px 0px 0px;" +
"-fx-font-family:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;");
}
super.updateSelected(selected);
}
@Override
protected void updateItem(String item, boolean empty)
{
super.updateItem(item, empty);
setText(item);
}
};
}
});
root.getChildren().add(comboBox);
System.out.println("Creo el combobox");
Scene scene = new Scene(root);
String cssURL = getClass().getResource("combo-box.css").toExternalForm();
scene.getStylesheets().add(cssURL);
System.out.println("Creo scene");
primaryStage.setScene(scene);
primaryStage.show();
System.out.println("Creo el combobox");
}
public static void main(String[] args) {
launch(args);
}
}
.css file
.tool-bar:horizontal {
-fx-background-color: #b3e6b3
}
#my-combo{
-fx-background-color: linear-gradient(to bottom,#5C5C5C, #1C1C1C);
-fx-border-color: #FFFFFF;
-fx-border-width: 1 1 1 1;
-fx-border-radius: 5 5 5 5;
-fx-padding:0 0 0 10;
}
#my-combo:hover{
-fx-background-color: linear-gradient(to bottom,#808080, #2E2E2E);
-fx-border-color:#C4D019;
}
#my-combo .arrow-button{
-fx-background-color: linear-gradient(to bottom,#5C5C5C, #1C1C1C);
-fx-padding:11 10 10 10;
-fx-background-radius: 5 5 5 5;
-fx-border-width:0 0 0 1;
-fx-border-color:#222323;
}
#my-combo .arrow-button:hover{
-fx-background-color: linear-gradient(to bottom,#C4D019, #586F25);
}
#my-combo .arrow-button .arrow{
-fx-background-color: #FFFFFF;
}
/*#my-combo .list-cell {
-fx-font-family:Arial;
-fx-font-size: 14px;
-fx-text-fill: #FFFFFF;
-fx-background-color:darksalmon;
}*/