【问题标题】:How to fill second combobox on the basis of the value of 1st combobox dynamically in javafx如何在javafx中根据第一个组合框的值动态填充第二个组合框
【发布时间】:2015-10-08 12:50:24
【问题描述】:

我正在使用 javafx 并处理应用程序 CRUD。我在组合框中添加数据,当我从一个组合框中选择任何数据时,相关数据应显示在另一个组合框中。数据源是mysql。

【问题讨论】:

    标签: javafx-2


    【解决方案1】:

    这只是一个简单的示例,您需要将数据从 mysql 添加到组合框see this ? code 如果有的话,请发表评论?s。

    示例

    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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      • 2021-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多