• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Question to ComboBox

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
   }
}
 
mohammed omer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private ObservableList<M02Locations> list_CityIn_town ;

private ObservableList< M02_1Locations> ListonTableView;// this is for collect data to TableView Sharochka

   @FXML
   private TableView<M02_1Locations> tblInformacion;
   @FXML
   private TableColumn<M02_1Locations, Number> clmnIDtown;
   @FXML
   private TableColumn<M02_1Locations, M02Locations> clmnm02Locations;
   @FXML
   private TableColumn<M02_1Locations, String> clmntown;
---------------------------------------------------------------------------------------------------------------------------------------
   private void cmbCityInSharochka() {
                    conn = windows.coDB();
       list_CityIn_town = FXCollections.observableArrayList();
       M02Locations.showDataonTableViewLocationTown(conn, list_CityIn_town );
       cmbCity_IN_town.setItems(list_CityIn_town );
   }
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic