Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question JavaFX Combo Box Event Handler Help

Joined
May 24, 2016
Messages
27
I am really new to this JavaFX and I've been following a couple tutorials, I finally made my GUI and was able to load it up. The next step would be handling events which I have no idea how it works. I kind of get the idea on how it works, but I'm not too sure how you would properly add an event.

I'm using this tutorial ---> Tutorial - JavaFX for Beginners

But that only explains how the button event is handled.

I have a combo box of tree types and another combo box with tree locations. I'm trying to make it where if the user selects a tree, there will be limited options of locations on where they can cut.

So for example if someone selects Oak Tree then location combo box has only 3 options of locations. Or if someone selects Normal Tree there are 5 options of locations.

Does anyone know a way of implementing the events to the combo boxes?
 
Joined
Dec 10, 2014
Messages
3,332
I am really new to this JavaFX and I've been following a couple tutorials, I finally made my GUI and was able to load it up. The next step would be handling events which I have no idea how it works. I kind of get the idea on how it works, but I'm not too sure how you would properly add an event.

I'm using this tutorial ---> Tutorial - JavaFX for Beginners

But that only explains how the button event is handled.

I have a combo box of tree types and another combo box with tree locations. I'm trying to make it where if the user selects a tree, there will be limited options of locations on where they can cut.

So for example if someone selects Oak Tree then location combo box has only 3 options of locations. Or if someone selects Normal Tree there are 5 options of locations.

Does anyone know a way of implementing the events to the combo boxes?
You'll need to add a listener to the combobox, a ChangeListener would work well for what you're suggesting. In the ChangeListener event, you'd set the items of the other combobox.
 
Joined
May 24, 2016
Messages
27
Tried adding change listener but I keep getting multiple errors...

I need a source of a bot that handles the same process as I'm trying to do so I can understand it better. The tutorial that I'm using is not helping me what so ever and still don't understand. Also when you start the bot how do you perform the functions of the bot?

For example:
- Select Tree Type
- Select Location
- Select Banking

Then the bot performs the following action given with those 3 options <EXAMPLE: Normal Tree, Varrock, West Bank>
- Cuts nearest Normal Tree
- Banks near Location of cutting

User updates bot settings <EXAMPLE: Willows, Draynor, Draynor's Bank>
- Bot ends last settings and is updated with new settings
- Cuts nearest Willow Tree
- Banks near Location of cutting

Like I said before I'm new to this whole JavaFX thing.
 
12 year old normie
Joined
Jan 8, 2015
Messages
2,768
Put very simple, you could make 3 strings in your main class, create setters for them, then set values for them in your actionevent handler.

Only showing options based on what a user selects could be done (I assume) by just checking for what option is set and then just adding certain objects to the combobox based on that.
 
Joined
Jan 8, 2015
Messages
1,426
You'll need to add a listener to the combobox, a ChangeListener would work well for what you're suggesting. In the ChangeListener event, you'd set the items of the other combobox.

In regards to this, I presume creating arrays with locations per tree would do the trick.

The event listener grabs the tree and gets the right array of locations to place in the other combo, right?
 
Joined
May 24, 2016
Messages
27
Well does anyone want to skype me then and show me how its done? Cause I want it done the right way and not end up screwing up.

Skype User: beastly-scape
 
Client Developer
Joined
Oct 12, 2015
Messages
3,781
Have each enum extend an interface Woodcutting, set combobox Type to Woodcutting ComboBox<Woodcutting>.
Have a static method getLocations() within your tree enum which pulls an array of Locations and returns it as an ArrayList.

So for example:
OAK("Oak", new Location[]{ Location.LUMBRIDGE, Location.DRAYNOR})
public static ArrayList<Location> getLocations() { ... }
Then on change:
combobox.getItems().addAll(Trees.getLocations());
 
Sorry for the super shitty response I'm at work. Jump on the development Slack chat though.
 
Joined
May 24, 2016
Messages
27
Have each enum extend an interface Woodcutting, set combobox Type to Woodcutting ComboBox<Woodcutting>.
Have a static method getLocations() within your tree enum which pulls an array of Locations and returns it as an ArrayList.

So for example:
OAK("Oak", new Location[]{ Location.LUMBRIDGE, Location.DRAYNOR})
public static ArrayList<Location> getLocations() { ... }
Then on change:
combobox.getItems().addAll(Trees.getLocations());
 
Sorry for the super shitty response I'm at work. Jump on the development Slack chat though.

okay a little more convenient and understandable but I would join the chat but I'm getting no email
 
Mod Automation
Joined
Jul 26, 2013
Messages
3,053
okay a little more convenient and understandable but I would join the chat but I'm getting no email
Re-navigate to the page and there will be a link to resend the email confirmation. Be sure to check your spam folder too, though I doubt it would be sent there.
 
Top