Created
February 21, 2015 05:09
-
-
Save TheItachiUchiha/3c273164c04acdad34bc to your computer and use it in GitHub Desktop.
ListView Focus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example for SO question - https://stackoverflow.com/questions/28641559/how-does-the-behaviour-of-a-listview-work