| | |
Filling a ComboBox....
![]() |
•
•
Join Date: May 2003
Posts: 2
Reputation:
Solved Threads: 0
Hi,
I'm in a IntrotoOOP class at my school, and my instructor asked me to look up how to fill a Java Swing Class ComboBox with data from a MySql Database. Does anyone know? This question has been quite hard to find any answers on and I have been really bugged by it recently.
Thanks!
Fyrelion
P.S.Any help at all would be really appreciated!!
I'm in a IntrotoOOP class at my school, and my instructor asked me to look up how to fill a Java Swing Class ComboBox with data from a MySql Database. Does anyone know? This question has been quite hard to find any answers on and I have been really bugged by it recently.
Thanks!
Fyrelion
P.S.Any help at all would be really appreciated!!
•
•
Join Date: Jul 2009
Posts: 19
Reputation:
Solved Threads: 0
JAVA Syntax (Toggle Plain Text)
private static void queryCountry(){ JC_country.addItem("(Choose)"); try { String query = DBConnect.Select("addr_ref", "country, description", "region = ''", "country"); Statement stmt = DBConnect.getConnection().createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()){ JC_country.addItem(rs.getString(1)+"-"+rs.getString(2)); } rs.close(); stmt.close(); } catch (SQLException e) { e.printStackTrace(); } }
•
•
Join Date: Jul 2009
Posts: 19
Reputation:
Solved Threads: 0
[code = JAVA]
private JComboBox getJC_country(){
if(JC_country== null){
JC_country = new JComboBox();
JC_country.setSize(new Dimension(260, 20));
JC_country.setLocation(new Point(80, 230));
JC_country.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try{
if (JC_country.getSelectedItem().toString().equalsIgnoreCase("(Choose)") == true){
JC_country.removeAllItems();
queryCountry();
}//end of if
if (JC_country.getSelectedItem().toString().equalsIgnoreCase("(Choose)") == true){
Country_Code = "Nothing";
JC_region.removeAllItems();
queryRegion();
JC_region.setSelectedIndex(0);
JC_province.setSelectedIndex(0);
}//end of if
Country_Code = JC_country.getSelectedItem().toString().substring(0, JC_country.getSelectedItem().toString().indexOf("-"));
String Filter_By_Code = "select city_municipality,description from addr_ref " +
"where country = '"+Country_Code +"'" +
"and"+
" region != '' " +
"and"+
" province != '' " +
"and"+
" city_municipality != '' "+
"and"+
" brgy_village = '' " +
"and"+
" street = '' ";
try{
tableMain.setQuery(Filter_By_Code);
}catch(Exception exp){
}//end of try catch
JC_region.removeAllItems();
queryRegion();
JC_region.setSelectedIndex(0);
JC_province.setSelectedIndex(0);
}catch(Exception e){
}//end of try catch
}// end of actionPerformed
});
}//end of JC_country.addActionListener(new ActionListener(){
return JC_country;
}//end of method getJC_country()
[/code]
private JComboBox getJC_country(){
if(JC_country== null){
JC_country = new JComboBox();
JC_country.setSize(new Dimension(260, 20));
JC_country.setLocation(new Point(80, 230));
JC_country.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try{
if (JC_country.getSelectedItem().toString().equalsIgnoreCase("(Choose)") == true){
JC_country.removeAllItems();
queryCountry();
}//end of if
if (JC_country.getSelectedItem().toString().equalsIgnoreCase("(Choose)") == true){
Country_Code = "Nothing";
JC_region.removeAllItems();
queryRegion();
JC_region.setSelectedIndex(0);
JC_province.setSelectedIndex(0);
}//end of if
Country_Code = JC_country.getSelectedItem().toString().substring(0, JC_country.getSelectedItem().toString().indexOf("-"));
String Filter_By_Code = "select city_municipality,description from addr_ref " +
"where country = '"+Country_Code +"'" +
"and"+
" region != '' " +
"and"+
" province != '' " +
"and"+
" city_municipality != '' "+
"and"+
" brgy_village = '' " +
"and"+
" street = '' ";
try{
tableMain.setQuery(Filter_By_Code);
}catch(Exception exp){
}//end of try catch
JC_region.removeAllItems();
queryRegion();
JC_region.setSelectedIndex(0);
JC_province.setSelectedIndex(0);
}catch(Exception e){
}//end of try catch
}// end of actionPerformed
});
}//end of JC_country.addActionListener(new ActionListener(){
return JC_country;
}//end of method getJC_country()
[/code]
•
•
Join Date: Jul 2009
Posts: 19
Reputation:
Solved Threads: 0
[code = JAVA]
private JComboBox getJC_country(){
if(JC_country== null){
JC_country = new JComboBox();
JC_country.setSize(new Dimension(260, 20));
JC_country.setLocation(new Point(80, 230));
JC_country.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try{
if (JC_country.getSelectedItem().toString().equalsIgnoreCase("(Choose)") == true){
JC_country.removeAllItems();
queryCountry();
}//end of if
if (JC_country.getSelectedItem().toString().equalsIgnoreCase("(Choose)") == true){
Country_Code = "Nothing";
JC_region.removeAllItems();
queryRegion();
JC_region.setSelectedIndex(0);
JC_province.setSelectedIndex(0);
}//end of if
Country_Code = JC_country.getSelectedItem().toString().substring(0, JC_country.getSelectedItem().toString().indexOf("-"));
String Filter_By_Code = "select city_municipality,description from addr_ref " +
"where country = '"+Country_Code +"'" +
"and"+
" region != '' " +
"and"+
" province != '' " +
"and"+
" city_municipality != '' "+
"and"+
" brgy_village = '' " +
"and"+
" street = '' ";
try{
tableMain.setQuery(Filter_By_Code);
}catch(Exception exp){
}//end of try catch
JC_region.removeAllItems();
queryRegion();
JC_region.setSelectedIndex(0);
JC_province.setSelectedIndex(0);
}catch(Exception e){
}//end of try catch
}// end of actionPerformed
});
}//end of JC_country.addActionListener(new ActionListener(){
return JC_country;
}//end of method getJC_country()
[/code]
private JComboBox getJC_country(){
if(JC_country== null){
JC_country = new JComboBox();
JC_country.setSize(new Dimension(260, 20));
JC_country.setLocation(new Point(80, 230));
JC_country.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try{
if (JC_country.getSelectedItem().toString().equalsIgnoreCase("(Choose)") == true){
JC_country.removeAllItems();
queryCountry();
}//end of if
if (JC_country.getSelectedItem().toString().equalsIgnoreCase("(Choose)") == true){
Country_Code = "Nothing";
JC_region.removeAllItems();
queryRegion();
JC_region.setSelectedIndex(0);
JC_province.setSelectedIndex(0);
}//end of if
Country_Code = JC_country.getSelectedItem().toString().substring(0, JC_country.getSelectedItem().toString().indexOf("-"));
String Filter_By_Code = "select city_municipality,description from addr_ref " +
"where country = '"+Country_Code +"'" +
"and"+
" region != '' " +
"and"+
" province != '' " +
"and"+
" city_municipality != '' "+
"and"+
" brgy_village = '' " +
"and"+
" street = '' ";
try{
tableMain.setQuery(Filter_By_Code);
}catch(Exception exp){
}//end of try catch
JC_region.removeAllItems();
queryRegion();
JC_region.setSelectedIndex(0);
JC_province.setSelectedIndex(0);
}catch(Exception e){
}//end of try catch
}// end of actionPerformed
});
}//end of JC_country.addActionListener(new ActionListener(){
return JC_country;
}//end of method getJC_country()
[/code]
![]() |
Similar Threads
- SQL querry Combo Box Question (C#)
- need help in filling combobox or listbox with dataset (VB.NET)
- Filling a combobox with MySql data (Java)
- filling combobox with data stored in a table in sql server (VB.NET)
- Programatically create and fill ComboBoxes (C)
Other Threads in the Java Forum
- Previous Thread: problem with controlling JRadio button
- Next Thread: tabbedpane
| Thread Tools | Search this Thread |
-xlint actionlistener add android applet application array automation bank bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse equation error event fractal ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper idea image infinite int j2me j2seprojects java javac javaee javame javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main method mobile myregfun netbeans notdisplaying number online pearl printf problem program qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows xor





