Tuesday, November 15, 2016

Contoh Combo Box Sederhana

Berikut ini saya membuat contoh combo box yang berisi data teman-teman :

/**
 *
 * @author Joko Adianto
 */
public class JavaFXComboBox extends Application {
 
    @Override
    public void start(Stage primaryStage) {
        ComboBox<String> comboBox = new ComboBox<>();
        ObservableList<String> oblTeman = FXCollections.observableArrayList();
        comboBox.itemsProperty().setValue(oblTeman);
        oblTeman.addAll("Hannibal Lecter", "Three Fingers",
                "Saw Thooth", "Chucky", "Tiffany", "Anabelle");      
             
        StackPane root = new StackPane();
        root.getChildren().add(comboBox);
     
        Scene scene = new Scene(root, 300, 250);
     
        primaryStage.setTitle("Daftar Teman Masa Kecil");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
 
}

No comments:

Post a Comment