Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8120749

BUG ComboBox Java 8 b75

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • 8
    • 7u13
    • javafx
    • None
    • Windows 7 64 bits Enterprise. Service Pack 1.
      JVM - Java 8 b75.
      IDE Eclipse

      The ComboBox list-cell does not allow loading of images.
      Attached is a test project.

      file: ComboBoxTest.java

      public class ComboBoxTest extends Application {

      private AnchorPane root = new AnchorPane();

      @Override
      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);
      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:Arial; -fx-font-size:14px; -fx-text-fill: #FFFFFF;" +
      "-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>() {
      @Override 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);

      Scene scene = new Scene(root);
      String cssURL = getClass().getResource("combo-box.css").toExternalForm();
      scene.getStylesheets().add(cssURL);

      primaryStage.setScene(scene);
      primaryStage.show();
      }

      public static void main(String[] args) {
      launch(args);
      }
      }

      file: combo-box.css


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

      Thanks

            dgrieve David Grieve
            cmingojfx Carlos Mingo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: