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

[TableView] Right click on the scroll bar scrolls the content.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 8
    • 8
    • javafx
    • jdk 1.8.0 - b62

      Click with right mouse button on the scroll bar and see that content is scrolled.

      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.ContextMenu;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.input.ContextMenuEvent;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class BugTableViewRightClick extends Application {

          TableView<Person> testedControl;

          @Override
          public void start(Stage stage) {

              testedControl = new TableView<>();
              
              TableColumn tableColumnA = new TableColumn("First name");
              tableColumnA.setCellValueFactory(new PropertyValueFactory<Person,String>("firstName"));
              TableColumn tableColumnB = new TableColumn("Last name");
              tableColumnB.setCellValueFactory(new PropertyValueFactory<Person,String>("lastName"));
              
              testedControl.getColumns().addAll(tableColumnA, tableColumnB);
              
              ObservableList<Person> data = FXCollections.observableArrayList(
                  new Person("Jacob", "Smith", "jacob.smith@example.com"),
                  new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
                  new Person("Ethan", "Williams", "ethan.williams@example.com"),
                  new Person("Emma", "Jones", "emma.jones@example.com"),
                  new Person("Michael", "Brown", "michael.brown@example.com")
              );
              testedControl.setItems(data);
              
              testedControl.setMaxHeight(120d);
              testedControl.setPrefHeight(120d);
              
              final ContextMenu contextMenu = new ContextMenu();
              for (int i = 0; i < 3; i++) {
                  contextMenu.getItems().add(new MenuItem("Menu item - " + i));
              }

              testedControl.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
                  @Override
                  public void handle(ContextMenuEvent t) {
                      contextMenu.show(testedControl, t.getScreenX(), t.getScreenY());
                  }
              });

              HBox root = new HBox(20d);
              root.getChildren().add(testedControl);

              Scene scene = new Scene(root, 300, 250);

              stage.setScene(scene);
              stage.setTitle(System.getProperty("java.runtime.version") + "; " + System.getProperty("javafx.runtime.version"));
              stage.show();
          }

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

          public static class Person {
              private final SimpleStringProperty firstName;
              private final SimpleStringProperty lastName;
              private final SimpleStringProperty email;

              private Person(String fName, String lName, String email) {
                  this.firstName = new SimpleStringProperty(fName);
                  this.lastName = new SimpleStringProperty(lName);
                  this.email = new SimpleStringProperty(email);
              }

              public String getFirstName() {
                  return firstName.get();
              }

              public void setFirstName(String fName) {
                  firstName.set(fName);
              }

              public String getLastName() {
                  return lastName.get();
              }

              public void setLastName(String fName) {
                  lastName.set(fName);
              }
          }
      }

            miflemi Mick Fleming
            dzinkevi Dmitry Zinkevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: