Hey, a little other question. Did you have any idea why i cant add any element like button or label to a vbox? I use: VBox vb = new VBox(); Button btn = new Button("hello"); vb.getChildren().add(btn); //here i get an error at 'add' ????? 🤔
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
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.
johan bengtsson agreed. Also, the drop down list looks horrible after a value has been set. I spent quite a few minutes researching what was wrong before I just youtube'd a few videos and realized it was default behavior. Terrible. I don't think there's any reason anyone should ever use choicebox over combobox.
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 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: " + cb.getValue())); st.show(); } }
You can also change the satement cb.setValue("Apple"); AS cb.getSelectionModel().select(0) by doing this you can always set the value as first option in choice box even there is some changes in the list:D
Hello guys, while searching, i found one more method FXML where we can easily drag and drop the fields, so im a bit confused which method i should use- JAVAFX or FXML? Pls Help
Sorry, I have a question. If I set two ChoiceBox ,XChoiceBox and YChoiceBox. I add "a", "b", "c" in the XChoiceBox. I want YChoiceBox can display"1", "2", "3" when I Choice "a" in XChoiceBox, display "4", "5", "6" when I Choice "b" in XChoiceBox. How can I do in the code? Please forgive my poor English and hope someone can understand what I mean.
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)
Any idea how to stop the drop down menu from moving. It is hard to explain but see if you have 5 choices and you choose the 5th, and then click on the drop down menu again the menu will move up until the 5th choice. Best I got
If I am executing your code and clicking on the ChoiceBox, then the frame closes and I get the following Message: A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ILLEGAL_INSTRUCTION (0xc000001d) at pc=0x00007ff9151ccd21, pid=15820, tid=476 # # JRE version: Java(TM) SE Runtime Environment (13.0.2+8) (build 13.0.2+8) # Java VM: Java HotSpot(TM) 64-Bit Server VM (13.0.2+8, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64) # Problematic frame: # C [d3d9.dll+0xacd21] # # No core dump will be written. Minidumps are not enabled by default on client versions of Windows # # An error report file with more information is saved as: # C:\Users\user\path_of_folder\hs_err_pid15820.log # # If you would like to submit a bug report, please visit: # bugreport.java.com/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. I searched the web for this, but didn't find anything... Edit: I found the solution --> I had to set the memory dumb to little memory dumbs!
I just start learning to code, so I'm not 100% sure. I think the difference is "set" and "get". When you use get, you get the information, when you use set, you change/modify something (Google setter and getter methods to get more info)
*coughs while makng JavaFx tutorial* Sorry I got black lung from working in the mines xD
"meatballs is a fruit" - thenewboston 2015
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
THANK YOU GWEN STEFANI
thnx for the spelling of Bananas
Hey bucky, how about doing some tutorials about wiring that'll awesome thanks!
Hey, a little other question. Did you have any idea why i cant add any element like button or label to a vbox? I use:
VBox vb = new VBox();
Button btn = new Button("hello");
vb.getChildren().add(btn); //here i get an error at 'add' ????? 🤔
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
couldn't you simply do
"button.setOnAction(e -> System.out.println(choiceBox.get value()));"
instead???
yep I think he just made a new method to make it easier to understand(although I'm not sure it is).
hmmm
That is exactly how I remember to spell bananas too lol
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.
johan bengtsson agreed. Also, the drop down list looks horrible after a value has been set. I spent quite a few minutes researching what was wrong before I just youtube'd a few videos and realized it was default behavior. Terrible. I don't think there's any reason anyone should ever use choicebox over combobox.
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 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:
" + cb.getValue()));
st.show();
}
}
You can also change the satement
cb.setValue("Apple");
AS
cb.getSelectionModel().select(0)
by doing this you can always set the value as first option in choice box even there is some changes in the list:D
@thenewboston is there a way without the button? I know JavaFX is dying due to jdk11 but anyway
How do you capture the data and use it in a different method instead of just printing what was clicked on?
Hello guys, while searching, i found one more method FXML where we can easily drag and drop the fields, so im a bit confused which method i should use- JAVAFX or FXML? Pls Help
Sorry, I have a question.
If I set two ChoiceBox ,XChoiceBox and YChoiceBox.
I add "a", "b", "c" in the XChoiceBox.
I want YChoiceBox can display"1", "2", "3" when I Choice "a" in XChoiceBox, display "4", "5", "6" when I Choice "b" in XChoiceBox.
How can I do in the code?
Please forgive my poor English and hope someone can understand what I mean.
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)
Any idea how to stop the drop down menu from moving. It is hard to explain but see if you have 5 choices and you choose the 5th, and then click on the drop down menu again the menu will move up until the 5th choice. Best I got
If I am executing your code and clicking on the ChoiceBox, then the frame closes and I get the following Message: A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ILLEGAL_INSTRUCTION (0xc000001d) at pc=0x00007ff9151ccd21, pid=15820, tid=476
#
# JRE version: Java(TM) SE Runtime Environment (13.0.2+8) (build 13.0.2+8)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (13.0.2+8, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C [d3d9.dll+0xacd21]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\user\path_of_folder\hs_err_pid15820.log
#
# If you would like to submit a bug report, please visit:
# bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
I searched the web for this, but didn't find anything...
Edit: I found the solution --> I had to set the memory dumb to little memory dumbs!
lol.. if you reload the page yo will see the views go up!
Why no one dont show how to do this with FXML file?
CheckBox.setValue now accepts every String
2020 update: It was Corona Virus.
i wish you continue the videos using eclipse , the dark background really bad in these videos, appreciate it buky
Ctrl+D copies line in intellij :3
what's the difference between box1.setItems and box1.getItems ?
I just start learning to code, so I'm not 100% sure. I think the difference is "set" and "get". When you use get, you get the information, when you use set, you change/modify something (Google setter and getter methods to get more info)
*its apple.... ZZZZ* im dead
You can easily tell this guy is not a developer.
LizardanNet how so?
+LizardanNet If your one then how come your watching a this tutorial
Actually he is a project leader for a JAVA team of developers
yes because he works in the mines