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

TableView Column header and column content go out of alignment when scrolled and maximized.

    Details

      Description

      Related bugs:

      RT-36832 Styled table cells get temporarily out of alignment with headers


      Problem:

      Column labels and column contents go out of alignment when horizontal scrollbar was scrolled and then maximize the window. The column headers are shifted to the left.

      Procedure:
      Run the code bellow
      Adjust the window size so that the horizontal scrollbar is visible
      Scroll to the right.
      Maximize the window.



      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.layout.HBox;
      import javafx.scene.text.Font;
      import javafx.stage.Stage;
       
      public class table extends Application {
          HBox root = new HBox();
          private TableView<Person> table = new TableView<Person>();
          private final 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")
              );
       
          public static void main(String[] args) {
              launch(args);
          }
       
          @Override
          public void start(Stage stage) {
              Scene scene = new Scene(new Group());
              double weight = scene.getWidth();;
              double height=scene.getHeight();
              stage.setTitle("Table View Sample");
              stage.setWidth(weight);
              stage.setHeight(height);
              table.setEditable(true);
              TableColumn firstNameCol = new TableColumn("First Name");
              firstNameCol.setMinWidth(500);
              firstNameCol.setCellValueFactory(
                      new PropertyValueFactory<Person, String>("firstName"));
       
              TableColumn lastNameCol = new TableColumn("Last Name");
              lastNameCol.setMinWidth(500);
              lastNameCol.setCellValueFactory(
                      new PropertyValueFactory<Person, String>("lastName"));
       
              TableColumn emailCol = new TableColumn("Email");
              emailCol.setMinWidth(1000);
              emailCol.setCellValueFactory(
                      new PropertyValueFactory<Person, String>("email"));
       
              table.setItems(data);
              table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
              root.getChildren().addAll(table);
              scene = new Scene(root, weight, height, true);
              stage.setScene(scene);
              stage.show();
          }
       
          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);
              }
       
              public String getEmail() {
                  return email.get();
              }
       
              public void setEmail(String fName) {
                  email.set(fName);
              }
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported: