JavaFX Java GUI Tutorial – 12 – ChoiceBox (Drop Down Menu)

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

19 responses to “JavaFX Java GUI Tutorial – 12 – ChoiceBox (Drop Down Menu)”

  1. Tobias Kolb Avatar

    @thenewboston is there a way without the button? I know JavaFX is dying due to jdk11 but anyway

  2. Immortal Legends Avatar

    Also, you can do without making methods,

    public class Main extends Application{
    public static void main(String[] args){
    launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
    Stage st = new Stage();
    st.setTitle("Choice box");
    VBox vx = new VBox(20);
    ChoiceBox<String> cb = new ChoiceBox<>();
    cb.getItems().addAll("Apple","Banana","Grapes","Leechi","Juice");
    Button B = new Button("Buy");
    vx.getChildren().addAll(new Label("Select the items you wan to buy"),cb ,B);
    st.setScene(new Scene(vx ,300 ,250));
    cb.setValue("Apple");
    B.setOnAction(e-> System.out.println("Orders are:n" + cb.getValue()));
    st.show();
    }
    }

  3. toon pomme Avatar

    thank you for this tutorial, the way of talkign is great compared to some other dev youtube tutos direct and to the point ! thanks alot

  4. Cubing Unlocked Avatar

    couldn't you simply do
    "button.setOnAction(e -> System.out.println(choiceBox.get value()));"
    instead???

  5. Protocycle_X Avatar

    5:34 thank god you failed there so that I could know what would happen if I didn't put an existent value xD (just watching the vids before trying alone)

  6. DanPan Avatar

    "meatballs is a fruit" – thenewboston 2015

  7. Harshit Singhai Avatar

    what's the difference between box1.setItems and box1.getItems ?

  8. Galacticore Avatar

    When using the lambda, you can skip making a method for returning a value by just using .getValue() method on your ChoiceBox, inside the print method.

    (e -> System.out.print(myChoiceBox.getValue()))

  9. Gurpreet Nanda Avatar

    coughs while makng JavaFx tutorial Sorry I got black lung from working in the mines xD

  10. Ezra Magaram Avatar

    At 4:10 you say that bacon, ham and meatballs are your favorite fruits

  11. Apex Window Cleaning Services Avatar

    That is exactly how I remember to spell bananas too lol

  12. Jeroen Koorenhof Avatar

    THANK YOU GWEN STEFANI

  13. johan bengtsson Avatar

    ComboBox was faster for me. (For a list of 100+ countries.) Looks almost identical, but you get better scroll functionality which is almost a must if you have lots of values.

  14. Hesham Scorpe Avatar

    thnx for the spelling of Bananas

  15. NorthernH Avatar

    wouldn't it be better to initialize an array of Strings and pass it as a parameter of the choiceBox instead? it may help you to organize your program better

  16. MonadicBind Avatar

    You can easily tell this guy is not a developer.

  17. Lazic B. Avatar

    Ok. Tutorial looks fine. However, I strongly recommend not to use setValue() to set default value for ChoiceBox. Why? What if you are dynamicaly populating ChoiceBox (from database for instance)? You cannot know that value will be even fetched from database (what if it was deleted before fetching). So instead of setValue, use: choiceBox.getSelectionModel().select(0);
    This way you are setting first value from ChoiceBox as a default, whatever that value is.

  18. The CheesyBocajLayon Avatar

    lol.. if you reload the page yo will see the views go up!

  19. Moon2s Avatar

    Hey bucky, how about doing some tutorials about wiring that'll awesome thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *