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

Incorrect text fill in ListCell set as the ComboBox#setButtonCell

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u40
    • javafx
    • None

      Running the snippet below renders the text in the label set as the graphic in white instead of black

      package org.eclipse.fx.code.compensator.project.vcs.git;

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ComboBox;
      import javafx.scene.control.Label;
      import javafx.scene.control.ListCell;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class TestMe extends Application {

      @Override
      public void start(Stage primaryStage) throws Exception {
      BorderPane p = createComboSample();

      Button b = new Button("Open Dialog");
      p.setBottom(b);

      Scene s = new Scene(p, 300, 300);
      primaryStage.setScene(s);
      primaryStage.show();
      }

      private static BorderPane createComboSample() {
      BorderPane p = new BorderPane();

      ComboBox<String> box = new ComboBox<>(FXCollections.observableArrayList("A","B","C"));
      box.setButtonCell(new ListCell<String>() {
      @Override
      protected void updateItem(String item, boolean empty) {
      if( item != null && ! empty ) {
      setGraphic(new Label(item));
      } else {
      setGraphic(null);
      }
      super.updateItem(item, empty);
      }
      });
      box.getSelectionModel().select(0);
      p.setCenter(box);

      return p;
      }

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

      I've tested this in u5 and u20 and there there the behavior is also wrong. I have not yet found out who the label is rendered in white. The only work around in found was to add the following css rule to my stylesheet.

      .combo-box > .list-cell > .label {
      -fx-text-fill: -fx-text-base-color;
      }

            Unassigned Unassigned
            tschindl Tom Schindl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported: