您好,我在ComboBox
中有一个MainController
声明,我想在ComboBox
中传递来自该ConexionController
的所有数据
cargavistauno
中的方法ConexionController
我正在研究中发现了这样的东西
public void cargavistauno(){
try {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("CargaDatosGenero.fxml"));
Scene scene = new Scene(fxmlLoader.load());
Main Controller = fxmlLoader.<Main>getController();
Controller.llenadocombobox();
fxmlLoader.setController(Controller);
Stage stage = new Stage();
stage.setTitle("Datos Del Cliente");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
}
}
我在Maincontroller
中有此方法,也有ComboBox
@FXML private ComboBox <String> combo;
@Override
public void start(Stage stage) {
try {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("Vista.fxml"));
Scene scene = new Scene(fxmlLoader.load());
fxmlLoader.setController(combo);
stage.setTitle("Project Xcorpio");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
}
}
public void llenadocombobox() {
Connection conn=null;
try {
ObservableList<String> listacombo= FXCollections.observableArrayList();
String consulta = "select genero from super";
conn = DriverManager.getConnection("jdbc:sqlserver://DESKTOP-TUP82C7:1433;databaseName=prueba", "sa", "milkas87");
PreparedStatement ps =conn.prepareStatement(consulta);
ResultSet rs = ps.executeQuery();
while ( rs.next() )
{
listacombo.add(rs.getString("genero"));
}
combo.setItems(listacombo);
} catch (SQLException e) {
e.printStackTrace();
}
}
如何传递这些值?任何需要的方向或帮助。谢谢。