JavaFX Tutorial 11 - ComboBox & ObservableList and ChoiceBox

Опубликовано: 18 Октябрь 2024
на канале: Code Amir
2,009
20

JavaFX Tutorial 11 ComboBox & ObservableList and ChoiceBox
Code Source
@Override
public void start(Stage primaryStage) {
HBox h = new HBox();
// Combobox
ComboBox cb = new ComboBox();
cb.setValue("Amir");
cb.getItems().addAll("Milan","Sara","Adam");
// ObservabeList
ArrayList l = new ArrayList();

for (int i =1 ; i=10 ; i++){
l.add(i+ "");
}

ObservableList list = FXCollections.observableList(l);
ComboBox cb2 = new ComboBox(list);
// Choicebox
ChoiceBox cb3 =new ChoiceBox();
cb3.getItems().addAll("1","2","3","4","5");


h.getChildren().addAll(cb,cb2,cb3);
Scene sc = new Scene(h,600,400);
primaryStage.setScene(sc);
primaryStage.setTitle("Tutorial JavaFX");
primaryStage.show();
}
Libraries Importing :
import java.util.ArrayList;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

The JavaFX ComboBox control enables users to choose an option from a predefined list of choices, or type in another value if none of the predefined choices matches what the user want to select. The JavaFX ComboBox control is represented by the class javafx.scene.control.ComboBox . This JavaFX ComboBox tutorial will explain how to use the ComboBox class.

The JavaFX ChoiceBox control enables users to choose an option from a predefined list of choices. The JavaFX ChoiceBox control is represented by the class javafx.scene.control.ChoiceBox . This JavaFX ChoiceBox tutorial will explain how to use the ChoiceBox class.

The JavaFX ListView control enables users to choose one or more options from a predefined list of choices. The JavaFX ListView control is represented by the class javafx.scene.control.ListView . This JavaFX ListView tutorial will explain how to use the ListView class.