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

TableView should use USE_PREF_SIZE

XMLWordPrintable

    • x86_64
    • linux

      A DESCRIPTION OF THE REQUEST :
      TableView uses an VirtualFlow to calculate the ViewPort
      wenn use tablewView in Layouts (TabPane / GridPane)
      in some cases it is needed, that the Table schows all items
      -> the TableView size must set as ViewPort size

      JUSTIFICATION :
      open detail.png:
      an Detail Tab shows additional informations over an Item

      in every Tab in this Detail it shows an TableView wird linked items:
      * an Items has a place
      * a place has items on it
      * user has groups / rights
      * ...

      in this Detail it is needed that only one Scrpallpane is Present
      so alle Tabs / Tableview in tabPane must use USE_PREF_SIZE
      to set width / heigt so that all items are directly visible


      ---------- BEGIN SOURCE ----------
      http://194.25.240.197:9980/MemoryTable.zip
      [add Tabs] / [add Cells]
      use [hack] to active the height / width calculation
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      // wait Skin is set
      view.skinProperty().addListener((ov, from, to) -> {
      try {
      // cast
      final TableViewSkin<?> skin = (TableViewSkin<?>) to;
      // ugly hack 1: get VirtualFlow
      final Field flowField = VirtualContainerBase.class.getDeclaredField("flow");
      flowField.setAccessible(true);
      final VirtualFlow<?> flow = (VirtualFlow<?>) flowField.get(skin);

      // ugly hack 2: get Methods to calc real ViewPort size
      final Method getMaxCellWidth = VirtualContainerBase.class.getDeclaredMethod("getMaxCellWidth", int.class);
      getMaxCellWidth.setAccessible(true);
      final Method getVirtualFlowPreferredHeight = VirtualContainerBase.class.getDeclaredMethod("getVirtualFlowPreferredHeight", int.class);
      getVirtualFlowPreferredHeight.setAccessible(true);

      final InvalidationListener invalidation = (value) -> {
      Platform.runLater(() -> {
      try {
      // ugly hack 3: calc ViewPort size
      final double width = (double) getMaxCellWidth.invoke(skin, view.getItems().size()) + 15;
      final double height = (double) getVirtualFlowPreferredHeight.invoke(skin, view.getItems().size()) + 15 + skin.getTableHeaderRow().getHeight();

      // set Size on tyble View
      // no space on bottom
      // only needed ells are created
      view.setMinSize(width, height);
      view.setPrefSize(width, height);
      view.setMaxSize(width, height);

      System.out.println(width + " " + height);
      } catch (final Throwable throwable) {
      throwable.printStackTrace();
      }
      });
      };

      // invalidations to trigger the calculation
      flow.widthProperty().addListener(invalidation);
      flow.heightProperty().addListener(invalidation);
      view.itemsProperty().addListener(invalidation);

      for (final TableColumn<?, ?> tc : view.getColumns()) {
      tc.widthProperty().addListener(invalidation);
      }
      } catch (final Throwable throwable) {
      throwable.printStackTrace();
      }
      });

        1. image001.png
          image001.png
          51 kB
        2. image002.png
          image002.png
          52 kB
        3. image003.png
          image003.png
          124 kB

            jgiles Jonathan Giles
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: