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

TableCells display Spurious Values when Scrolling with Mousewheel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 8
    • javafx
    • Windows 8, using Lombard build 92

      Run the following code:

      import javafx.application.Application;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.*;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;
      import javafx.util.Callback;


      public class MouseWheelVisibilityBug extends Application {
         
         public static void main(String[] args) {
             launch(args);
         }
             
         @Override public void start(Stage primaryStage) {
             primaryStage.setTitle("Mousewheel Visibility Bug");
             StackPane root = new StackPane();
             root.getChildren().add( buildTable() );
             primaryStage.setScene(new Scene(root, 150, 250));
             primaryStage.show();
         }
           
         private TableView buildTable() {
             
            // create table with a bunch of rows
            TableView<Boolean> table = new TableView<>();
            for ( int i = 1; i <= 500; i++ ) {
               table.getItems().add(false);
            }
            final TableColumn<Boolean, Boolean> column = new TableColumn<>("Column");
            column.setPrefWidth( 100 );
            table.getColumns().setAll( column );

            // each cell in the column simply contains a checkbox whose visibility
            // is bound to the cell's mouse 'hover' property
            column.setCellFactory(
               new Callback<TableColumn<Boolean,Boolean>, TableCell<Boolean,Boolean>>() {
               public TableCell<Boolean, Boolean> call(
                  TableColumn<Boolean, Boolean> c ) {
                  return new TableCell<Boolean, Boolean>() {
                     {
                        final CheckBox cb = new CheckBox();
                        setGraphic( cb );
                        setAlignment( Pos.CENTER );
                        cb.visibleProperty().bind( hoverProperty() );
                     }
                  };
               }
            });
              
            return table;
         }
           
      }

      ------------

      This code creates a simple table with 500 items, displayed in 10 rows and 1 column. Every TableCell has a Checkbox, whose visibility is bound to the TableCells hoverProperty(). In other words, the CheckBox for a given cell is visible iff the mouse is hovering over that cell. Cells do NOT display the actual items() in the table; for brevity there is no CellValueFactory in this example.

      To see the bug:

      1) Run the sample program. Move the mouse around the column to see the visibility of checkboxes change.

      2) Grab the scrollbar button (do not use the scrollwheel yet) and drag up and down. No checkboxes are visible while you do this, which is as it should be.

      3) Now put the mouse over the column and start scrolling down and up with the mousewheel. After a short time of doing this, you'll be able to get a condition where more than one cell has a visible checkbox! This shouldn't be possible.

      4) Once you're in this state, go back to the scrollbar button and start dragging it up and down again. Now you've got lots of visible checkboxes, which is even more impossible.

      --------------------------------

      This bug is probably very closely related to bug RT-31252 that I reported yesterday:

      https://javafx-jira.kenai.com/browse/RT-31252

            jgiles Jonathan Giles
            cbanackjfx Cory Banack (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: