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

[TreeView] string converter is called, but not applied

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 7u6
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Environment:

      2.2.0b15

      Description

      Run code, press button.

      import javafx.application.Application;
      import javafx.beans.property.SimpleBooleanProperty;
      import javafx.beans.value.ObservableValue;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeView;
      import javafx.scene.control.cell.CheckBoxTreeCell;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.Callback;
      import javafx.util.StringConverter;

      public class Main extends Application {

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

          @Override
          public void start(Stage stage) throws Exception {
              VBox vb = new VBox();

              final TreeView lv = new TreeView();
              lv.setRoot(new TreeItem(new DataItem()));

              Button b = new Button("Press me");
              b.setOnAction(new EventHandler<ActionEvent>() {

                  public void handle(ActionEvent t) {
                      Callback<TreeItem<DataItem>, ObservableValue<Boolean>> callback1 = new Callback<TreeItem<DataItem>, ObservableValue<Boolean>>() {

                          public ObservableValue<Boolean> call(final TreeItem<DataItem> p) {
                              return p.getValue().someData;
                          }
                      };
                      lv.setCellFactory(CheckBoxTreeCell.forTreeView(callback1, new CellCustomStringConverter()));
                  }
              });

              vb.getChildren().addAll(lv, b);

              Scene scene = new Scene(vb, 300, 300);
              stage.setScene(scene);
              stage.show();
          }

          class DataItem {

              public ObservableValue<Boolean> someData = new SimpleBooleanProperty(true);
          }

          public class CellCustomStringConverter extends StringConverter {

              public static final String TO_STRING_PREFIX = "tsc ";
              public static final String FROM_STRING_PREFIX = "fsc ";

              @Override
              public String toString(Object t) {
                  System.out.println("Called to string");
                  return TO_STRING_PREFIX + t != null ? t.toString() : "null";
              }

              @Override
              public Object fromString(String string) {
                  System.out.println("called from string");
                  return null;
              }
          }
      }

      I expect to see "tsc " prefix before presented items' names.

        Attachments

          Activity

            People

            • Assignee:
              jgiles Jonathan Giles
              Reporter:
              akirov Alexander Kirov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: