Created
July 12, 2015 02:38
-
-
Save ahn94/427efd72271e3101025b to your computer and use it in GitHub Desktop.
ComboBox is useful
This file contains hidden or 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.application.Platform; | |
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; | |
ComboBox<String> comboBox; | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage primaryStage) { | |
window = primaryStage; | |
window.setTitle("Austin"); | |
button = new Button("Click Me"); | |
comboBox = new ComboBox<>(); | |
comboBox.getItems().addAll( | |
"Good", | |
"Better", | |
"Best", | |
"Crappy", | |
"Shitty" | |
); | |
comboBox.setPromptText("How do you rate it?"); | |
comboBox.setOnAction(e -> System.out.println("User selected: " + comboBox.getValue())); | |
button.setOnAction(e -> printMovie()); | |
comboBox.setEditable(true); | |
//Layout | |
VBox layout = new VBox(10); | |
layout.setPadding(new Insets(20, 20, 20, 20)); | |
layout.getChildren().addAll(comboBox, button); | |
Scene scene = new Scene(layout, 300, 250); | |
window.setScene(scene); | |
window.show(); | |
} | |
private void printMovie(){ | |
System.out.println(comboBox.getValue()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment