JDK-8115476 : TableView: horizontal scrollbar and additional right table column header when CONSTRAINED_RESIZE_POLICY is used
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-07-30
  • Updated: 2019-08-02
  • Resolved: 2013-08-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Fixed
Related Reports
Relates :  
Relates :  
Description
When CONSTRAINED_RESIZE_POLICY is set on a TableView an additional empty table column header and a horizontal scrollbar can appear. Here is an example to demonstrate the behavior:
_________________________________________________________
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.SnapshotResult;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Callback;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;

public class TableViewSizeDemo extends Application {


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

	@Override
	public void start(final Stage stage) throws Exception {
		stage.setTitle("TableView Demo");

		VBox pane = new VBox();
		pane.setPadding(new Insets(10));

		ObservableList<Person> items = FXCollections.observableArrayList(people(100));
		final TableView<Person> tableView = new TableView<>(items);
		tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

		final TableColumn<Person, String> firstNameColumn = new TableColumn<>("First Name");
		firstNameColumn.setCellValueFactory(new PropertyValueFactory<>("firstName"));
		final TableColumn<Person, String> lastNameColumn = new TableColumn<>("Last Name");
		lastNameColumn.setCellValueFactory(new PropertyValueFactory<>("lastName"));

		tableView.getColumns().addAll(firstNameColumn, lastNameColumn);

		Button button = new Button("take snapshot");
		button.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(final ActionEvent event) {

				WritableImage wim = new WritableImage(300, 500);
				stage.getScene().snapshot(new Callback<SnapshotResult, Void>() {
					@Override
					public Void call(final SnapshotResult param) {
						try {
							ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", new File("tableview_constrained_resize_policy.png"));
						} catch (IOException e) {
							e.printStackTrace();
						}
						return null;
					}
				}, wim);


			}
		});

		pane.getChildren().addAll(tableView, button);

		Scene scene = new Scene(pane, 300, 500, Color.DODGERBLUE);
		stage.setScene(scene);
		stage.show();
	}

	public static ObservableList<Person> people(int howMany) {
		ObservableList<Person> result = FXCollections.observableArrayList();
		for (int i = 0; i < howMany; i++) {
			result.add(new Person("firstname " + i, "lastname " + i));

		}
		return result;
	}

	public static class Person {
		private final String firstName;
		private final String lastName;

		public Person(final String firstName, final String lastName) {
			this.firstName = firstName;
			this.lastName = lastName;
		}

		public String getFirstName() {
			return firstName;
		}

		public String getLastName() {
			return lastName;
		}
	}

}

_________________________________________________________

I think it would make sense that the additional table column header would never appear and then
also the horizontal scrollbar should not appear.

With the current behavior when the horizontal scrollbar is moved to the right the additional column header appears. Also note that when the table loses the focus the horizontal scrollbar moves to the left but the
additional column header stays visible.




Comments
for fx11, the horizontal scrollbar still appears with constrained resizing, both this example (even showing initially) and the example (flickering on/off when resizing the table) in the earlier (reported 2011!!) JDK-8089280 Regression? or never really fixed? or problem with highDPI?
02-08-2019