i have a project with JavaFX in NetBeans
i have come combobox
i want to link it
for example i want to select ( Town ) from Second ComboBox according to the selected (City) in first ComboBox
////////////////////////////////////////////////////////////////////////////////////////////////////
package db_mor.Model;
import com.sun.jdi.connect.spi.Connection;
import db_mor.windows;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import javafx.scene.control.Alert;
/**
*
* @author nawba
*/
public class M02_1Locations {
private IntegerProperty IDsharochka;
public M02Locations m02Locations;
private StringProperty sharochka;
public M02_1Locations(int IDsharochka, M02Locations m02Locations,
String sharochka) {
this.IDsharochka = new SimpleIntegerProperty(IDsharochka);
this.m02Locations = m02Locations;
this.sharochka = new SimpleStringProperty(sharochka);
}
public M02_1Locations(IntegerProperty IDsharochka, StringProperty sharochka) {
this.IDsharochka = IDsharochka;
this.sharochka = sharochka;
}
//Metodos atributo: IDsharochka
public int getIDsharochka() {
return IDsharochka.get();
}
public void setIDsharochka(int IDsharochka) {
this.IDsharochka = new SimpleIntegerProperty(IDsharochka);
}
public IntegerProperty IDsharochkaProperty() {
return IDsharochka;
}
//Metodos atributo: m02Locations
public M02Locations getM02Locations() {
return m02Locations;
}
public void setM02Locations(M02Locations m02Locations) {
this.m02Locations = m02Locations;
}
//Metodos atributo: sharochka
public String getSharochka() {
return sharochka.get();
}
public void setSharochka(String sharochka) {
this.sharochka = new SimpleStringProperty(sharochka);
}
public StringProperty SharochkaProperty() {
return sharochka;
}
//
public static void showDataonTableViewLocationTown(java.sql.Connection connection, ObservableList<M02_1Locations> list) {
try {
Statement statement = connection.createStatement();
ResultSet resultado = statement.executeQuery("SELECT `IDtown`, `city`, `sharochka` FROM `tbl_02_02town`");
while (resultado.next()) {
list.add(
new M02_1Locations(resultado.getInt("IDtown"),
new M02Locations(resultado.getInt("city"), resultado.getString("city")), resultado.getString("town"))
);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void llenarInformationsTableView(java.sql.Connection connection, ObservableList<M02_1Locations> list) {
try {
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(
"SELECT A.`IDtown`,"
+ " B.`city`,B.`IDcity`, A.`town` "
+ "FROM `tbl_02_02town` A "
+ "INNER JOIN tbl_02_01city B ON (A.city = B.IDcity)" );
while (rs.next()) {
list.add(
new M02_1Locations(rs.getInt("IDtown"),
new M02Locations(rs.getInt("IDcity"), rs.getString("city")), rs.getString("town"))
);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public int insertIntoDBTown(java.sql.Connection coDB) {
try {
PreparedStatement statement = coDB.prepareStatement(
"INSERT INTO `tbl_02_02sharochka` (`city`,`town`) VALUES (?,?);");
statement.setInt(1, m02Locations.getIDcity());
statement.setString(2, town.get());
return statement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
return 0;
}
}
@Override
public String toString() {
return town.get();
}
}