-
Bug
-
Resolution: Unresolved
-
P4
-
8
-
8.0b69
Run the attached code:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class JavaFXApplication16 extends Application {
TreeTableView<Data> treeTableView;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
treeTableView = new TreeTableView<Data>();
treeTableView.setRoot(new TreeItem<>(new Data("Root")));
treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 1")));
treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 2")));
treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 3")));
treeTableView.getRoot().setExpanded(true);
treeTableView.getColumns().add(new TreeTableColumn<>("Data"));
((TreeTableColumn<Data, String>) treeTableView.getColumns().get(0)).setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Data,String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Data, String> p) {
return p.getValue().getValue().property;
}
});
Button b = new Button("remove");
b.setOnAction(new EventHandler() {
@Override
public void handle(Event t) {
treeTableView.getRoot().getChildren().remove(treeTableView.getRoot().getChildren().size() - 1);
}
});
Button b1 = new Button("print selection");
b1.setOnAction(new EventHandler() {
@Override
public void handle(Event t) {
System.out.println("selected item : " + treeTableView.getSelectionModel().getSelectedItem());
}
});
treeTableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue ov, Object t, Object t1) {
System.out.println("Changed selection to " + t1);
}
});
VBox vb = new VBox();
vb.getChildren().addAll(b, b1, treeTableView);
Scene scene = new Scene(vb, 300, 300);
stage.setScene(scene);
stage.show();
}
class Data {
public StringProperty property;
public Data(String data) {
property = new SimpleStringProperty(data);
}
@Override
public String toString() {
return property.get();
}
}
}
Selected the last item (item 3) and click button remove.
Note, that there is no any output.
Click button "print selection" and you will see, that removed item is still selected.
I expect, that selection should be cleared.
Affected tests:
ControlsAutomatedTestSuite/javafx/scene/control/test/treetable/TreeTableAsOldTreeTest/removeTest
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class JavaFXApplication16 extends Application {
TreeTableView<Data> treeTableView;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
treeTableView = new TreeTableView<Data>();
treeTableView.setRoot(new TreeItem<>(new Data("Root")));
treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 1")));
treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 2")));
treeTableView.getRoot().getChildren().add(new TreeItem<Data>(new Data("item 3")));
treeTableView.getRoot().setExpanded(true);
treeTableView.getColumns().add(new TreeTableColumn<>("Data"));
((TreeTableColumn<Data, String>) treeTableView.getColumns().get(0)).setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Data,String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Data, String> p) {
return p.getValue().getValue().property;
}
});
Button b = new Button("remove");
b.setOnAction(new EventHandler() {
@Override
public void handle(Event t) {
treeTableView.getRoot().getChildren().remove(treeTableView.getRoot().getChildren().size() - 1);
}
});
Button b1 = new Button("print selection");
b1.setOnAction(new EventHandler() {
@Override
public void handle(Event t) {
System.out.println("selected item : " + treeTableView.getSelectionModel().getSelectedItem());
}
});
treeTableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue ov, Object t, Object t1) {
System.out.println("Changed selection to " + t1);
}
});
VBox vb = new VBox();
vb.getChildren().addAll(b, b1, treeTableView);
Scene scene = new Scene(vb, 300, 300);
stage.setScene(scene);
stage.show();
}
class Data {
public StringProperty property;
public Data(String data) {
property = new SimpleStringProperty(data);
}
@Override
public String toString() {
return property.get();
}
}
}
Selected the last item (item 3) and click button remove.
Note, that there is no any output.
Click button "print selection" and you will see, that removed item is still selected.
I expect, that selection should be cleared.
Affected tests:
ControlsAutomatedTestSuite/javafx/scene/control/test/treetable/TreeTableAsOldTreeTest/removeTest
- relates to
-
JDK-8248217 ☂ TreeTableView selection issues
- Open