Details
Description
ADDITIONAL SYSTEM INFORMATION :
MacOS
A DESCRIPTION OF THE PROBLEM :
When non-leaf tree nodes are populated only when required it leads to the selection of an incorrect node. This only occurs when the folder being opened is above the selection. If the folder is below the selection, nothing untoward happens.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided code.
1) Click open arrow on Folder 4 (10 items appear)
2) Select item 2
3) Click open arrow on Folder 2 (or any folder above the current selection)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Folder 2 should open, the selection on Folder 4 / Item 2 should remain as it was.
ACTUAL -
Folder 2 opens.
Folder 4 / Item 2 changes to an outline, and Folder 4 / Item 8 is selected.
It appears that the selection moves down by twice the number of items in the newly opened folder - in this case three items times two means the selection moves down six items.
---------- BEGIN SOURCE ----------
package com.bytezone.bugs;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
// -----------------------------------------------------------------------------------//
public class Bug001 extends Application
// -----------------------------------------------------------------------------------//
{
// ---------------------------------------------------------------------------------//
@Override
public void start (Stage primaryStage) throws Exception
// ---------------------------------------------------------------------------------//
{
primaryStage.setTitle ("Hello World!");
BugTreeItem rootItem = new BugTreeItem ("Root");
rootItem.setExpanded (true);
for (int j = 1; j < 5; j++)
{
BugTreeItem folderItem = new BugTreeItem ("Folder " + j);
rootItem.getChildren ().add (folderItem);
}
TreeView<String> tree = new TreeView<String> (rootItem);
StackPane root = new StackPane ();
root.getChildren ().add (tree);
primaryStage.setScene (new Scene (root, 400, 600));
primaryStage.show ();
}
// ---------------------------------------------------------------------------------//
public static void main (String[] args)
// ---------------------------------------------------------------------------------//
{
launch (args);
}
}
package com.bytezone.bugs;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TreeItem;
// -----------------------------------------------------------------------------------//
public class BugTreeItem extends TreeItem<String>
// -----------------------------------------------------------------------------------//
{
boolean firstTimeChildren = true;
// ---------------------------------------------------------------------------------//
public BugTreeItem (String text)
// ---------------------------------------------------------------------------------//
{
super (text);
}
// ---------------------------------------------------------------------------------//
@Override
public boolean isLeaf ()
// ---------------------------------------------------------------------------------//
{
return getValue ().startsWith ("Item");
}
// ---------------------------------------------------------------------------------//
@Override
public ObservableList<TreeItem<String>> getChildren ()
// ---------------------------------------------------------------------------------//
{
if (firstTimeChildren)
{
firstTimeChildren = false;
if (getValue ().startsWith ("F"))
super.getChildren ().setAll (buildChildren ());
}
return super.getChildren ();
}
// ---------------------------------------------------------------------------------//
private ObservableList<BugTreeItem> buildChildren ()
// ---------------------------------------------------------------------------------//
{
ObservableList<BugTreeItem> children = FXCollections.observableArrayList ();
int max = getValue ().equals ("Folder 4") ? 10 : 3;
for (int i = 0; i < max; i++)
children.add (new BugTreeItem ("Item " + i));
return children;
}
}
---------- END SOURCE ----------
FREQUENCY : always
MacOS
A DESCRIPTION OF THE PROBLEM :
When non-leaf tree nodes are populated only when required it leads to the selection of an incorrect node. This only occurs when the folder being opened is above the selection. If the folder is below the selection, nothing untoward happens.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided code.
1) Click open arrow on Folder 4 (10 items appear)
2) Select item 2
3) Click open arrow on Folder 2 (or any folder above the current selection)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Folder 2 should open, the selection on Folder 4 / Item 2 should remain as it was.
ACTUAL -
Folder 2 opens.
Folder 4 / Item 2 changes to an outline, and Folder 4 / Item 8 is selected.
It appears that the selection moves down by twice the number of items in the newly opened folder - in this case three items times two means the selection moves down six items.
---------- BEGIN SOURCE ----------
package com.bytezone.bugs;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
// -----------------------------------------------------------------------------------//
public class Bug001 extends Application
// -----------------------------------------------------------------------------------//
{
// ---------------------------------------------------------------------------------//
@Override
public void start (Stage primaryStage) throws Exception
// ---------------------------------------------------------------------------------//
{
primaryStage.setTitle ("Hello World!");
BugTreeItem rootItem = new BugTreeItem ("Root");
rootItem.setExpanded (true);
for (int j = 1; j < 5; j++)
{
BugTreeItem folderItem = new BugTreeItem ("Folder " + j);
rootItem.getChildren ().add (folderItem);
}
TreeView<String> tree = new TreeView<String> (rootItem);
StackPane root = new StackPane ();
root.getChildren ().add (tree);
primaryStage.setScene (new Scene (root, 400, 600));
primaryStage.show ();
}
// ---------------------------------------------------------------------------------//
public static void main (String[] args)
// ---------------------------------------------------------------------------------//
{
launch (args);
}
}
package com.bytezone.bugs;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TreeItem;
// -----------------------------------------------------------------------------------//
public class BugTreeItem extends TreeItem<String>
// -----------------------------------------------------------------------------------//
{
boolean firstTimeChildren = true;
// ---------------------------------------------------------------------------------//
public BugTreeItem (String text)
// ---------------------------------------------------------------------------------//
{
super (text);
}
// ---------------------------------------------------------------------------------//
@Override
public boolean isLeaf ()
// ---------------------------------------------------------------------------------//
{
return getValue ().startsWith ("Item");
}
// ---------------------------------------------------------------------------------//
@Override
public ObservableList<TreeItem<String>> getChildren ()
// ---------------------------------------------------------------------------------//
{
if (firstTimeChildren)
{
firstTimeChildren = false;
if (getValue ().startsWith ("F"))
super.getChildren ().setAll (buildChildren ());
}
return super.getChildren ();
}
// ---------------------------------------------------------------------------------//
private ObservableList<BugTreeItem> buildChildren ()
// ---------------------------------------------------------------------------------//
{
ObservableList<BugTreeItem> children = FXCollections.observableArrayList ();
int max = getValue ().equals ("Folder 4") ? 10 : 3;
for (int i = 0; i < max; i++)
children.add (new BugTreeItem ("Item " + i));
return children;
}
}
---------- END SOURCE ----------
FREQUENCY : always
Attachments
Issue Links
- duplicates
-
JDK-8331554 Mouse click on TreeView open triangle causes unnecessary selection
- Closed
- relates to
-
JDK-8290348 TreeTableView jumping to top
- Resolved