I think I've found some odd scroll behaviours while playing a bit with the TableView...
The following lines of code will replicate the issues that I've found when displaying cells with multiple lines:
import java.io.CharArrayWriter;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class TableViewTest extends Application {
public class LogEntry {
private int lineNumber;
private String description;
public LogEntry(int lineNumber, String text) {
this.lineNumber = lineNumber;
this.description = text;
}
public int getLineNumber() {
return lineNumber;
}
public String getDescription() {
return description;
}
}
@Override
public void start(Stage stage) {
TableView<LogEntry> tableView = new TableView<LogEntry>();
TableColumn<LogEntry, Integer> lineNumberColumn = new TableColumn<LogEntry, Integer>();
lineNumberColumn.setText("Line Number");
lineNumberColumn.setCellValueFactory(new PropertyValueFactory<LogEntry, Integer>("lineNumber"));
tableView.getColumns().add(lineNumberColumn);
TableColumn<LogEntry, String> descriptionColumn = new TableColumn<LogEntry, String>();
descriptionColumn.setText("Description");
descriptionColumn.setCellValueFactory(new PropertyValueFactory<LogEntry, String>("description"));
tableView.getColumns().add(descriptionColumn);
tableView.setItems(createEntries());
stage.setScene(new Scene(tableView, 800, 600));
stage.setTitle("TableView Test");
stage.show();
}
protected ObservableList<LogEntry> createEntries() {
char ch = 'A';
int maxCharsPerLine;
CharArrayWriter textWriter = new CharArrayWriter();
ObservableList<LogEntry> entries = FXCollections.<LogEntry>observableArrayList();
for (int entryIndex=0; entryIndex<26; entryIndex++) {
maxCharsPerLine = 290 + 30*entryIndex;
for (int charIndex=0; charIndex<10000; charIndex++) {
textWriter.append(ch);
if (charIndex > 0 && charIndex % maxCharsPerLine == 0) {
textWriter.append('\n');
}
}
entries.add(new LogEntry(entryIndex + 1, textWriter.toString()));
textWriter.reset();
ch++;
}
return entries;
}
public static void main(String[] args) {
Application.launch(args);
}
}
The createEntries() method will create 26 dummy log entries. Each LogEntry is identified by a line number and has a description that contains multiple lines.
Each cell will contain 10.000 chars and a max of 10000/290 ~= 35 lines with a max of 290 + 30*25 = 1040 chars per line. I know that the max number of chars per line it's a bit exagerated, but I always like to test with BIG/exagerated values
After the application starts, take a look at the scroll bar size (without maximizing the window). You will notice that it doesn't look right... And you will also notice that, while you scroll, it will change size, which is a very odd behaviour!
Another thing that I've noticed is that the scroll performance seems to degrade while we scroll further down.
The following lines of code will replicate the issues that I've found when displaying cells with multiple lines:
import java.io.CharArrayWriter;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class TableViewTest extends Application {
public class LogEntry {
private int lineNumber;
private String description;
public LogEntry(int lineNumber, String text) {
this.lineNumber = lineNumber;
this.description = text;
}
public int getLineNumber() {
return lineNumber;
}
public String getDescription() {
return description;
}
}
@Override
public void start(Stage stage) {
TableView<LogEntry> tableView = new TableView<LogEntry>();
TableColumn<LogEntry, Integer> lineNumberColumn = new TableColumn<LogEntry, Integer>();
lineNumberColumn.setText("Line Number");
lineNumberColumn.setCellValueFactory(new PropertyValueFactory<LogEntry, Integer>("lineNumber"));
tableView.getColumns().add(lineNumberColumn);
TableColumn<LogEntry, String> descriptionColumn = new TableColumn<LogEntry, String>();
descriptionColumn.setText("Description");
descriptionColumn.setCellValueFactory(new PropertyValueFactory<LogEntry, String>("description"));
tableView.getColumns().add(descriptionColumn);
tableView.setItems(createEntries());
stage.setScene(new Scene(tableView, 800, 600));
stage.setTitle("TableView Test");
stage.show();
}
protected ObservableList<LogEntry> createEntries() {
char ch = 'A';
int maxCharsPerLine;
CharArrayWriter textWriter = new CharArrayWriter();
ObservableList<LogEntry> entries = FXCollections.<LogEntry>observableArrayList();
for (int entryIndex=0; entryIndex<26; entryIndex++) {
maxCharsPerLine = 290 + 30*entryIndex;
for (int charIndex=0; charIndex<10000; charIndex++) {
textWriter.append(ch);
if (charIndex > 0 && charIndex % maxCharsPerLine == 0) {
textWriter.append('\n');
}
}
entries.add(new LogEntry(entryIndex + 1, textWriter.toString()));
textWriter.reset();
ch++;
}
return entries;
}
public static void main(String[] args) {
Application.launch(args);
}
}
The createEntries() method will create 26 dummy log entries. Each LogEntry is identified by a line number and has a description that contains multiple lines.
Each cell will contain 10.000 chars and a max of 10000/290 ~= 35 lines with a max of 290 + 30*25 = 1040 chars per line. I know that the max number of chars per line it's a bit exagerated, but I always like to test with BIG/exagerated values
After the application starts, take a look at the scroll bar size (without maximizing the window). You will notice that it doesn't look right... And you will also notice that, while you scroll, it will change size, which is a very odd behaviour!
Another thing that I've noticed is that the scroll performance seems to degrade while we scroll further down.