-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8
-
x86_64
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.16299.309]
A DESCRIPTION OF THE PROBLEM :
A JavaFX TableView allows you to reorder columns by dragging and dropping them. However, if several adjacent columns are set invisible (using TableColumn.setVisibile(false)), and then you attempt to drag and drop a visible column past these invisible columns, the visible column does not end up where the gui indicates it should. This is because the drag and drop behaviour does not account for invisible columns.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a TableView with columns "one", "two", "three", "four" and "five", where columns "two" and "three" are set invisible (using TableColumn.setVisible(false)).
2. Run your application, then drag column "one" to the position between columns"four" and "five". This will result in column "one" not moving.
3. If you print out the column list while doing this (using TableView.getColumns()), then you will observe that the new column order is actually "two", "three" "one", "four", "five" instead of the expected "two", "three", "four", "one", "five".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting the column order to be "two", "three", "four", "one", "five".
ACTUAL -
The actual column order is "two", "three" "one", "four", "five".
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package javafxplayground;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
public class BrokenTableView extends Application {
@Override
public void start(final Stage stage) throws Exception {
final TableView table = new TableView();
final TableColumn colOne = new TableColumn("Column1");
final TableColumn colTwo = new TableColumn("Column2");
colTwo.setVisible(false);
final TableColumn colThree = new TableColumn("Column3");
colThree.setVisible(false);
final TableColumn colFour = new TableColumn("Column4");
final TableColumn colFive = new TableColumn("Column5");
table.getColumns().addAll(colOne, colTwo, colThree, colFour, colFive);
final ObservableList<List<String>> data = FXCollections.observableArrayList();
data.add(Arrays.asList("1", "2", "3", "4", "5"));
data.add(Arrays.asList("a", "b", "c", "d", "e"));
table.setItems(data);
System.out.println("Initial column order: "
+ table.getColumns().stream()
.map(column -> ((TableColumn) column).getText())
.collect(Collectors.toList()));
table.getColumns().addListener((final Change c) -> {
System.out.println("Column order changed to: "
+ c.getList().stream()
.map(column -> ((TableColumn) column).getText())
.collect(Collectors.toList()));
});
Scene scene = new Scene(table, 400, 300);
stage.setScene(scene);
stage.show();
}
public static void main(final String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.16299.309]
A DESCRIPTION OF THE PROBLEM :
A JavaFX TableView allows you to reorder columns by dragging and dropping them. However, if several adjacent columns are set invisible (using TableColumn.setVisibile(false)), and then you attempt to drag and drop a visible column past these invisible columns, the visible column does not end up where the gui indicates it should. This is because the drag and drop behaviour does not account for invisible columns.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a TableView with columns "one", "two", "three", "four" and "five", where columns "two" and "three" are set invisible (using TableColumn.setVisible(false)).
2. Run your application, then drag column "one" to the position between columns"four" and "five". This will result in column "one" not moving.
3. If you print out the column list while doing this (using TableView.getColumns()), then you will observe that the new column order is actually "two", "three" "one", "four", "five" instead of the expected "two", "three", "four", "one", "five".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting the column order to be "two", "three", "four", "one", "five".
ACTUAL -
The actual column order is "two", "three" "one", "four", "five".
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package javafxplayground;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
public class BrokenTableView extends Application {
@Override
public void start(final Stage stage) throws Exception {
final TableView table = new TableView();
final TableColumn colOne = new TableColumn("Column1");
final TableColumn colTwo = new TableColumn("Column2");
colTwo.setVisible(false);
final TableColumn colThree = new TableColumn("Column3");
colThree.setVisible(false);
final TableColumn colFour = new TableColumn("Column4");
final TableColumn colFive = new TableColumn("Column5");
table.getColumns().addAll(colOne, colTwo, colThree, colFour, colFive);
final ObservableList<List<String>> data = FXCollections.observableArrayList();
data.add(Arrays.asList("1", "2", "3", "4", "5"));
data.add(Arrays.asList("a", "b", "c", "d", "e"));
table.setItems(data);
System.out.println("Initial column order: "
+ table.getColumns().stream()
.map(column -> ((TableColumn) column).getText())
.collect(Collectors.toList()));
table.getColumns().addListener((final Change c) -> {
System.out.println("Column order changed to: "
+ c.getList().stream()
.map(column -> ((TableColumn) column).getText())
.collect(Collectors.toList()));
});
Scene scene = new Scene(table, 400, 300);
stage.setScene(scene);
stage.show();
}
public static void main(final String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8186512 TableView: column reordering is not working properly when there are invisible columns
-
- Closed
-