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

[ListView, TableView] string converter is not applicable.

    Details

      Description

      Run Code:

      import com.sun.javafx.scene.control.cell.StringConverterCellFactory;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.StringConverter;

      public class JavaApplication33 extends Application {

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

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

              CustomStringConverter sc = new CustomStringConverter();

              System.out.println("SC : " + sc);

              lv.setCellFactory(StringConverterCellFactory.forListView(sc));

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

          class CustomStringConverter extends StringConverter {

              public static final String TO_STRING_PREFIX = "to string convert ";
              public static final String FROM_STRING_PREFIX = "from string convert ";
              public static final String MID_STRING_PREFIX = " of item ";
              int toStringCounter = 0;
              int fromStringCounter = 0;

              @Override
              public String toString(Object t) {
                  return TO_STRING_PREFIX + toStringCounter++ + MID_STRING_PREFIX + t.toString();
              }

              @Override
              public Object fromString(String string) {
                  return FROM_STRING_PREFIX + fromStringCounter++ + MID_STRING_PREFIX + string;
              }
          }
      }

      I see exception:
      SC : javaapplication33.JavaApplication33$CustomStringConverter@b3ed2e3
      Exception in Application start method
      Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
      at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
      at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
      at java.lang.Thread.run(Thread.java:722)
      Caused by: java.lang.IllegalArgumentException: StringConverter must not be null
      at com.sun.javafx.scene.control.cell.StringConverterListCell.<init>(StringConverterListCell.java:38)
      at com.sun.javafx.scene.control.cell.StringConverterCellFactory$1.call(StringConverterCellFactory.java:62)
      at com.sun.javafx.scene.control.cell.StringConverterCellFactory$1.call(StringConverterCellFactory.java:60)
      at com.sun.javafx.scene.control.skin.ListViewSkin.createCell(ListViewSkin.java:189)
      at com.sun.javafx.scene.control.skin.ListViewSkin$1.call(ListViewSkin.java:63)
      at com.sun.javafx.scene.control.skin.ListViewSkin$1.call(ListViewSkin.java:61)
      at com.sun.javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1476)
      at com.sun.javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1502)
      at com.sun.javafx.scene.control.skin.VirtualFlow$3.call(VirtualFlow.java:478)
      at com.sun.javafx.scene.control.skin.VirtualFlow$3.call(VirtualFlow.java:476)
      at com.sun.javafx.scene.control.skin.PositionMapper.computeViewportOffset(PositionMapper.java:143)
      at com.sun.javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:986)
      at javafx.scene.Parent.layout(Parent.java:1003)
      at javafx.scene.Parent.layout(Parent.java:1013)
      at javafx.scene.Parent.layout(Parent.java:1013)
      at javafx.scene.Parent.layout(Parent.java:1013)
      at javafx.scene.Scene.layoutDirtyRoots(Scene.java:500)
      at javafx.scene.Scene.doLayoutPass(Scene.java:473)
      at javafx.scene.Scene.preferredSize(Scene.java:1245)
      at javafx.scene.Scene.impl_preferredSize(Scene.java:1272)
      at javafx.stage.Window$10.invalidated(Window.java:719)
      at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:129)
      at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:163)
      at javafx.stage.Window.setShowing(Window.java:782)
      at javafx.stage.Window.show(Window.java:797)
      at javafx.stage.Stage.show(Stage.java:229)
      at javaapplication33.JavaApplication33.start(JavaApplication33.java:39)
      at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
      at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:175)
      at com.sun.javafx.application.PlatformImpl$3.run(PlatformImpl.java:142)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
      ... 1 more
      Java Result: 1

      That is actual for ListView and TableView

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: