Skip to content

Instantly share code, notes, and snippets.

@TheItachiUchiha
Created February 21, 2015 05:09
Show Gist options
  • Save TheItachiUchiha/3c273164c04acdad34bc to your computer and use it in GitHub Desktop.
Save TheItachiUchiha/3c273164c04acdad34bc to your computer and use it in GitHub Desktop.
ListView Focus
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
HBox group = new HBox();
ObservableList items = FXCollections.observableArrayList("abc", "def", "ghi", "xyz");
ListView<String> listView1 = new ListView<String>(items);
ListView<String> listView2 = new ListView<String>(items);
listView1.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("ListView1 - " + newValue.toString());
System.out.println("ListView2 - " + listView2.getSelectionModel().getSelectedItem());
});
listView2.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("ListView2 - " + newValue.toString());
System.out.println("ListView1 - " + listView1.getSelectionModel().getSelectedItem());
});
group.getChildren().addAll(listView1, listView2);
primaryStage.setTitle("ListView Focus");
primaryStage.setScene(new Scene(group, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
@TheItachiUchiha
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment