i am using javafx and working on a application CRUD. i nedd data in a combobox and when i select any of the data from one combobox the related data should be display on another combobox. the data source is mysql.
Asked
Active
Viewed 59 times
1 Answers
0
This is just a simple example you need to add data form mysql to combo box see this ? code post a comment if any ?s.
Example
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Table extends Application {
private Stage primaryStage;
private AnchorPane pane;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("AddressApp");
VBox v = new VBox(10);
ComboBox<String> c = new ComboBox<String>();
ComboBox<String> c1 = new ComboBox<String>();
ObservableList<String> sList = FXCollections.observableArrayList();
sList.addAll("b", "c", "dd", "dcd", "dddf");
c.setItems(sList);
c1.setItems(sList);
// c1.valueProperty().bind(c.valueProperty());
c1.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
c.setValue(newValue);
}
});
v.getChildren().addAll(c, c1);
Scene Scene = new Scene(v);
primaryStage.setScene(Scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

Community
- 1
- 1

Gaali Prabhakar
- 583
- 6
- 23