From falcon.sheep at gmail.com Wed Apr 1 05:02:35 2020 From: falcon.sheep at gmail.com (Abu Abdullah) Date: Wed, 1 Apr 2020 09:02:35 +0400 Subject: Regression bug in TreeView.getSelectionModel().getSelectedItem() Message-ID: Hi, I have old application on jfx bundled with oracle jdk 1.8 working fine. i have upgraded it to the latest jfx14 but found the following issue: TreeView.getSelectionModel().getSelectedItem() returns null eventhough that TreeView.getSelectionModel().getSelectedItems().size() = 1 code is like: ********************************* TreeView.getSelectionModel().getSelectedItems(). addListener(new ListChangeListener>() { @Override public void onChanged(Change> change) { int i = TreeView.getSelectionModel().getSelectedItems().size(); // i =1 TreeItem node = TreeView.getSelectionModel().getSelectedItem(); // node = null } }); ************************************ in the bundled version of jfx, it was working as expected and im able to retrieve the object. From dlemmermann at gmail.com Wed Apr 1 10:05:11 2020 From: dlemmermann at gmail.com (Dirk Lemmermann) Date: Wed, 1 Apr 2020 12:05:11 +0200 Subject: Regression bug in TreeView.getSelectionModel().getSelectedItem() In-Reply-To: References: Message-ID: <0EAD1437-B1C5-4A18-9AFF-45A1C59FF1E4@gmail.com> You are listening to the changes made to the ?list" of selected items but then you are using the ?selectedItem? property. If the list gets updated BEFORE the ?selectedItem? value was set then your code will fail. Adding to the list and setting the property is not an atomic operation. If this worked before then you were simply lucky. Newer versions of JavaFX might have rearranged the sequence of updates which causes this ?regression?. But I think those were allowed changes. There is no contract that says that the ?selectedItem? needs to be set before the list gets updated. Or am I missing something? Dirk > On 1 Apr 2020, at 07:02, Abu Abdullah wrote: > > Hi, > > I have old application on jfx bundled with oracle jdk 1.8 working fine. > > i have upgraded it to the latest jfx14 but found the following issue: > > TreeView.getSelectionModel().getSelectedItem() returns null eventhough that > TreeView.getSelectionModel().getSelectedItems().size() = 1 > > code is like: > ********************************* > TreeView.getSelectionModel().getSelectedItems(). > addListener(new ListChangeListener>() > { > @Override > public void onChanged(Change> change) > { > int i = TreeView.getSelectionModel().getSelectedItems().size(); > // i =1 > > TreeItem node = TreeView.getSelectionModel().getSelectedItem(); > // node = null > } > }); > ************************************ > > in the bundled version of jfx, it was working as expected and im able to > retrieve the object. From falcon.sheep at gmail.com Wed Apr 1 11:37:53 2020 From: falcon.sheep at gmail.com (Abu Abdullah) Date: Wed, 1 Apr 2020 15:37:53 +0400 Subject: Regression bug in TreeView.getSelectionModel().getSelectedItem() In-Reply-To: <0EAD1437-B1C5-4A18-9AFF-45A1C59FF1E4@gmail.com> References: <0EAD1437-B1C5-4A18-9AFF-45A1C59FF1E4@gmail.com> Message-ID: On Wed, Apr 1, 2020 at 2:05 PM Dirk Lemmermann wrote: > You are listening to the changes made to the ?list" of selected items but > then you are using the ?selectedItem? property. If the list gets updated > BEFORE the ?selectedItem? value was set then your code will fail. Adding to > the list and setting the property is not an atomic operation. > > If this worked before then you were simply lucky. Newer versions of JavaFX > might have rearranged the sequence of updates which causes this > ?regression?. But I think those were allowed changes. There is no contract > that says that the ?selectedItem? needs to be set before the list gets > updated. > > Or am I missing something? > Thank you for your response, certainly the list is not updated between the 2 calls. it just works all the time in older version but not once in newer version. But I forgot very important condition. clicking normally on the tree just works fine (correct behavior) in all versions in the same way. the one that is not working is when programmatically select a tree node using: ************************* tree.getSelectionModel().clearSelection(); tree.getSelectionModel().select(node); final int row = tree.getRow(node); tree.scrollTo(row); ************************* From dlemmermann at gmail.com Wed Apr 1 12:02:24 2020 From: dlemmermann at gmail.com (Dirk Lemmermann) Date: Wed, 1 Apr 2020 14:02:24 +0200 Subject: Regression bug in TreeView.getSelectionModel().getSelectedItem() In-Reply-To: References: <0EAD1437-B1C5-4A18-9AFF-45A1C59FF1E4@gmail.com> Message-ID: <622743C9-0B48-42F8-A5CF-84B4FB5B5507@gmail.com> There is a difference between doing this programmatically or via interaction with the UI. But this is somewhat too low level for me and I hope somebody else can answer how and when observables are updated. I assume it has something to do with the pulse? Dirk > On 1 Apr 2020, at 13:37, Abu Abdullah wrote: > > On Wed, Apr 1, 2020 at 2:05 PM Dirk Lemmermann > wrote: > You are listening to the changes made to the ?list" of selected items but then you are using the ?selectedItem? property. If the list gets updated BEFORE the ?selectedItem? value was set then your code will fail. Adding to the list and setting the property is not an atomic operation. > > If this worked before then you were simply lucky. Newer versions of JavaFX might have rearranged the sequence of updates which causes this ?regression?. But I think those were allowed changes. There is no contract that says that the ?selectedItem? needs to be set before the list gets updated. > > Or am I missing something? > > Thank you for your response, certainly the list is not updated between the 2 calls. it just works all the time in older version but not once in newer version. > > But I forgot very important condition. clicking normally on the tree just works fine (correct behavior) in all versions in the same way. the one that is not working is when programmatically select a tree node using: > ************************* > tree.getSelectionModel().clearSelection(); > tree.getSelectionModel().select(node); > > final int row = tree.getRow(node); > tree.scrollTo(row); > ************************* > > From fastegal at swingempire.de Wed Apr 1 14:37:49 2020 From: fastegal at swingempire.de (Jeanette Winzenburg) Date: Wed, 01 Apr 2020 16:37:49 +0200 Subject: Regression bug in TreeView.getSelectionModel().getSelectedItem() In-Reply-To: References: <0EAD1437-B1C5-4A18-9AFF-45A1C59FF1E4@gmail.com> Message-ID: <20200401163749.Horde.mJbht7jAswN-PCMylH1BPw2@webmail.df.eu> my comment would have been the same as Dirk's :) As your original description changed between your first and second post, I would suggest you write a minimal, reproducible example that demonstrates what's _really_ going on in which context. If you think it's a bug, please file it (including the mcve) -- Jeanette Zitat von Abu Abdullah : > On Wed, Apr 1, 2020 at 2:05 PM Dirk Lemmermann > wrote: > >> You are listening to the changes made to the ?list" of selected items but >> then you are using the ?selectedItem? property. If the list gets updated >> BEFORE the ?selectedItem? value was set then your code will fail. Adding to >> the list and setting the property is not an atomic operation. >> >> If this worked before then you were simply lucky. Newer versions of JavaFX >> might have rearranged the sequence of updates which causes this >> ?regression?. But I think those were allowed changes. There is no contract >> that says that the ?selectedItem? needs to be set before the list gets >> updated. >> >> Or am I missing something? >> > > Thank you for your response, certainly the list is not updated between the > 2 calls. it just works all the time in older version but not once in newer > version. > > But I forgot very important condition. clicking normally on the tree just > works fine (correct behavior) in all versions in the same way. the one that > is not working is when programmatically select a tree node using: > ************************* > tree.getSelectionModel().clearSelection(); > tree.getSelectionModel().select(node); > > final int row = tree.getRow(node); > tree.scrollTo(row); > ************************* From falcon.sheep at gmail.com Sat Apr 11 16:58:51 2020 From: falcon.sheep at gmail.com (Abu Abdullah) Date: Sat, 11 Apr 2020 20:58:51 +0400 Subject: Regression bug in TreeView.getSelectionModel().getSelectedItem() In-Reply-To: <20200401163749.Horde.mJbht7jAswN-PCMylH1BPw2@webmail.df.eu> References: <0EAD1437-B1C5-4A18-9AFF-45A1C59FF1E4@gmail.com> <20200401163749.Horde.mJbht7jAswN-PCMylH1BPw2@webmail.df.eu> Message-ID: sample code that represent the issue ************************* import javafx.application.Application; import javafx.collections.ListChangeListener; import javafx.scene.Scene; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class TreeViewExample extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { TreeItem rootItem = new TreeItem<>("Tutorials"); TreeItem javaItem = new TreeItem<>("Java Tutorials"); TreeItem javaItem2 = new TreeItem<>("Java Language"); TreeItem javaItem3 = new TreeItem<>("Java Collections"); TreeItem javaItem4 = new TreeItem<>("Java Concurrency"); javaItem.getChildren().add(javaItem2); javaItem.getChildren().add(javaItem3); javaItem.getChildren().add(javaItem4); rootItem.getChildren().add(javaItem); TreeView treeView = new TreeView<>(); treeView.setRoot(rootItem); treeView.setShowRoot(false); VBox vbox = new VBox(treeView); Scene scene = new Scene(vbox); primaryStage.setScene(scene); primaryStage.show(); treeView.getSelectionModel().getSelectedItems().addListener(new ListChangeListener>() { @Override public void onChanged(Change> change) { int i = treeView.getSelectionModel().getSelectedItems().size(); System.out.println(i); // i =1 TreeItem node = treeView.getSelectionModel().getSelectedItem(); if (node == null) System.out.println("node is null"); // In javafx-14 with jdk-14 else System.out.println("node is not null"); // in javafx bundled with jdk-8 } }); treeView.getSelectionModel().clearSelection(); treeView.getSelectionModel().select(javaItem3); final int row = treeView.getRow(javaItem3); treeView.scrollTo(row); } } **************************** this is the important code: if (node == null) System.out.println("node is null"); // In javafx-14 with jdk-14 else System.out.println("node is not null"); // in javafx bundled with jdk-8 On Wed, Apr 1, 2020 at 6:38 PM Jeanette Winzenburg wrote: > > my comment would have been the same as Dirk's :) > > As your original description changed between your first and second > post, I would suggest you write a minimal, reproducible example that > demonstrates what's _really_ going on in which context. If you think > it's a bug, please file it (including the mcve) > > -- Jeanette > > Zitat von Abu Abdullah : > > > On Wed, Apr 1, 2020 at 2:05 PM Dirk Lemmermann > > wrote: > > > >> You are listening to the changes made to the ?list" of selected items > but > >> then you are using the ?selectedItem? property. If the list gets updated > >> BEFORE the ?selectedItem? value was set then your code will fail. > Adding to > >> the list and setting the property is not an atomic operation. > >> > >> If this worked before then you were simply lucky. Newer versions of > JavaFX > >> might have rearranged the sequence of updates which causes this > >> ?regression?. But I think those were allowed changes. There is no > contract > >> that says that the ?selectedItem? needs to be set before the list gets > >> updated. > >> > >> Or am I missing something? > >> > > > > Thank you for your response, certainly the list is not updated between > the > > 2 calls. it just works all the time in older version but not once in > newer > > version. > > > > But I forgot very important condition. clicking normally on the tree just > > works fine (correct behavior) in all versions in the same way. the one > that > > is not working is when programmatically select a tree node using: > > ************************* > > tree.getSelectionModel().clearSelection(); > > tree.getSelectionModel().select(node); > > > > final int row = tree.getRow(node); > > tree.scrollTo(row); > > ************************* > > > >