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

ComboBoxTableCell ListView doesn't resize correctly on content change

XMLWordPrintable

    • x86
    • other

      FULL PRODUCT VERSION :
      java version "1.8.0_92"
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Windows 10/Windows 7

      A DESCRIPTION OF THE PROBLEM :
      It is possible after multiple selections and certain actions for the comboboxtablecell to get into a state where the listview that contains the available items is opened in a much larger skin than is necessary. I'm not sure if null items are in the list, or if the skin of the editor is just not resized correctly.

      As background, an action causes the number of items in a comboboxtablecell to update. In our application it is that the choice in a comboboxtablecell in one column influences the items that are available in the comboboxtablecell in the next column for a given row. Something about clicking outside the combo editor to close it the first time round seems to cause the skin to not shrink correctly after this.

      the test app I have written below is a little contrived as I have used a button to update the contents of the cell. I was trying to make it as simple as possible.

      The steps for this are very subtle and it doesn't stop you doing anything, so I can't imagine that this is high priority. It just looks a little odd to our clients if they ever see it. We have found this to be quite reproducible in the table mentioned above with the two combo columns


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      • Open the test case application
      • Click in the only cell in the table. Click again to select and again to open (three clicks in total to get the editor for the combo to open)
      • There are 3 items in the combo list view
      • This is the key step. If you don't do this it doesn't reproduce. With the combo list view still open move the mouse off the editor and click somewhere else so it closes. On the table or in the rim of the dialog outside the table is fine
      • The combo list view closes
      • Click on the cell again to reopen the combo. There should be still 3 entries in the list view.
      • With the list view still open click on the button to change the entries in the combo.
      • The combo list view closes and the button is pressed.
      • Click on the cell again to reopen it. There should now be 6 entries.
      • With the list view still open click on the button again.
      • The combo list view closes and the button has been pressed.
      • Click on the cell again to reopen it. There are now only 3 items, but still space for 6.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect the combo listview to open sized correctly for the number of items inside it when I do the final switch from 6 back to 3 items
      ACTUAL -
      I'v switched from 3 items to 6, then back to 3, but there is still space for 6 in the skin of the editor that is opened. There are just 3 empty spaces below the 3 items in the editor

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TableCell;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.ComboBoxTableCell;
      import javafx.scene.layout.Region;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.Callback;


      public class ComboBoxTest extends Application {

          @Override
          public void start(final Stage primaryStage) throws Exception {

              primaryStage.centerOnScreen();
              primaryStage.setHeight(200);
              primaryStage.setWidth(300);

              ObservableList<String> list1 = FXCollections.observableArrayList();
              list1.add("one");
              list1.add("two");
              list1.add("three");

              ObservableList<String> list2 = FXCollections.observableArrayList();
              list2.add("four");
              list2.add("five");
              list2.add("six");
              list2.add("seven");
              list2.add("eight");
              list2.add("nine");

              TableView<Row> table = new TableView<>();
              table.setEditable(true);
              Row row = new Row();
              row.possibleRowValues.addAll(list1);

              TableColumn<Row, String> column = new TableColumn<>("col");
              column.setCellValueFactory(p -> p.getValue().selectedValue);
              column.setCellFactory(new Callback<TableColumn<Row, String>, TableCell<Row, String>>()
              {
                  @Override
                  public TableCell<Row, String> call(final TableColumn<Row, String> param)
                  {
                      return new ComboBoxTableCell(row.possibleRowValues);
                  }
              });

              table.getColumns().addAll(column);
              table.setItems(FXCollections.observableArrayList(row));

              Button button = new Button("Change combo contents");
              button.setOnAction(event -> {
                  if (row.possibleRowValues.size() == 3 ) {
                      row.possibleRowValues.clear();
                      row.possibleRowValues.addAll(list2);
                  } else {
                      row.possibleRowValues.clear();
                      row.possibleRowValues.addAll(list1);
                  }
              });

              VBox box = new VBox(20, table, button );
              box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
              primaryStage.setScene(new Scene( new StackPane(box) ));

              primaryStage.show();

          }

          private class Row
          {
              StringProperty selectedValue = new SimpleStringProperty("");
              ObservableList<String> possibleRowValues = FXCollections.observableArrayList();
          }

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

      }
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: