Description
It is possible to create two lists with different content and bind their selection models. So that, after selection in the second list, for any action (up down keys pressed) in the first list, curson in the first list will be set to 0-th item.
Steps to reproduce one of the problems:
1) Select 1st, 2nd, 3rd elements in the second list
2) Press "Left". You will be int he first list.
3) press "Down"
expected: 4th element is selected
got: 0-th is selected.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
/**
* @author alexander_kirov
*/
public class Main extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage stage)
{
HBox root = new HBox();
final ListView<String> listView1 = new ListView<String>();
final ListView<String> listView2 = new ListView<String>();
final ObservableList<String> items1 = FXCollections.observableArrayList(
"Jens", "Per", "Rolf", "Nils", "Ole");
final ObservableList<String> items2 = FXCollections.observableArrayList(
"Jens", "Per", "Rolf", "Nils", "Ole", "Jess");
listView1.setItems(items1);
listView2.setItems(items2);
listView1.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
listView2.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
listView1.selectionModelProperty().bindBidirectional(listView2.selectionModelProperty());
root.getChildren().addAll(listView1, listView2);
Scene scene = new Scene(root, 800, 600);
stage.setScene(scene);
stage.show();
}
}
Steps to reproduce one of the problems:
1) Select 1st, 2nd, 3rd elements in the second list
2) Press "Left". You will be int he first list.
3) press "Down"
expected: 4th element is selected
got: 0-th is selected.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
/**
* @author alexander_kirov
*/
public class Main extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage stage)
{
HBox root = new HBox();
final ListView<String> listView1 = new ListView<String>();
final ListView<String> listView2 = new ListView<String>();
final ObservableList<String> items1 = FXCollections.observableArrayList(
"Jens", "Per", "Rolf", "Nils", "Ole");
final ObservableList<String> items2 = FXCollections.observableArrayList(
"Jens", "Per", "Rolf", "Nils", "Ole", "Jess");
listView1.setItems(items1);
listView2.setItems(items2);
listView1.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
listView2.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
listView1.selectionModelProperty().bindBidirectional(listView2.selectionModelProperty());
root.getChildren().addAll(listView1, listView2);
Scene scene = new Scene(root, 800, 600);
stage.setScene(scene);
stage.show();
}
}