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

Text in cells doesn't change color when the cell is focussed, if the text is set in a node via setGraphic

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • fx2.1
    • fx2.1
    • javafx
    • Windows 7, JavaFX 2.1 b08

      This is a little bit hard to describe, but easy to understand, when you run the code.

      I often use CellFactories for my ListViews and Trees, because I usually display more than just text.

      I do that by using setGraphic and a custom node which meets my requirements.

      I recognized that when I do that, that the text color is not changed to white, when the cell is focussed.

      If I just use setText it works.

      This seem to affect every setGraphic method so far: TitledPane, ListView, TreeView





      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.ListCell;
      import javafx.scene.control.ListView;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.Callback;


      public class TestApp3 extends Application {
          public static void main(String[] args) throws Exception {
              launch(args);
          }

          public void start(final Stage stage) throws Exception {

              VBox root = new VBox();

              ListView<String> listView1 = new ListView<String>();
              listView1.setItems(FXCollections.observableArrayList("String1", "String2", "String3"));

              ListView<String> listView2 = new ListView<String>();
              listView2.setItems(FXCollections.observableArrayList("String1", "String2", "String3"));
              listView2.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
                  @Override
                  public ListCell<String> call(ListView<String> stringListView) {
                      ListCell<String> cell = new ListCell<String>() {
                          @Override
                          protected void updateItem(String item, boolean empty) {
                              super.updateItem(item, empty);
                              setText(item);
                              HBox hBox = new HBox();
                              hBox.getChildren().add(new Label(item));
                              setGraphic(hBox);
                          }

                      };
                      return cell;
                  }
              });

              root.getChildren().add(listView1);
              root.getChildren().add(listView2);

              Scene scene = new Scene(root);
              stage.setScene(scene);
              stage.show();
          }
      }

            jgiles Jonathan Giles
            cschudtjfx Christian Schudt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: