• Post Reply Bookmark Topic Watch Topic
  • New Topic

Set and get values of ChoiceBox created using Scene Builder?  RSS feed

 
Marcus Fernstrom
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using NetBeans and Scene Builder to build up my applications, and I can't figure out how to set and get values from a ChoiceBox that was created using Scene Builder.

All the examples I've found assumes that you're creating the ChoiceBox manually.
 
Marcus Fernstrom
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out how to do it.

In case another Java beginner finds it helpful:
public ChoiceBox modeSelect;
modeSelect.getSelectionModel().getSelectedItem().toString()
 
david brauer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I cannot get it to work still, please help me out   how do i set and get items from a choicebox?
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch,

Can you show the code you are using (please remember to use Code Tags when posting code).
 
John Damien Smith
Ranch Hand
Posts: 350
21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are creating the choice box in code, write:

If the choice box was created in FXML, in FXML you have:

And in code you have it injected using FXML by defining an item with a matching ID:

Either way the choice box will be created and a reference called choiceBox will be defined.
To get the items in the choice box:

To set the items in the choice box:

To get the selected item write:

To set the selected item write:


There is a tutorial by Oracle:
https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/choice-box.htm#BCEDJAEH





 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!