Skip to content

Instantly share code, notes, and snippets.

@ahn94
Created July 12, 2015 02:48
Show Gist options
  • Save ahn94/30af46cda9023b8868e8 to your computer and use it in GitHub Desktop.
Save ahn94/30af46cda9023b8868e8 to your computer and use it in GitHub Desktop.
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class Main extends Application {
Stage window;
Scene scene;
Button button;
ListView<String> listView;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
window = primaryStage;
window.setTitle("Austin");
button = new Button("Click Me");
listView = new ListView<>();
listView.getItems().addAll("Iron Man", "Titanic", "Contact", "Surrogates");
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
button.setOnAction(event -> buttonClicked());
//Layout
VBox layout = new VBox(10);
layout.setPadding(new Insets(20, 20, 20, 20));
layout.getChildren().addAll(listView, button);
Scene scene = new Scene(layout, 300, 250);
window.setScene(scene);
window.show();
}
private void buttonClicked(){
String message = "";
ObservableList<String> movies;
movies = listView.getSelectionModel().getSelectedItems();
for(String m: movies){
message += m + "\n";
}
System.out.println(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment