namsu55
asked on
How do I retrieve the value from the ComboBox which binds to the database.
In Netbeans I currently have a ComboBox. I bind the ComboBox to a table, it collects a column for me. How do I get the value of that column and use it throughout the program. I want to take for instance whatever is selected from the ComboBox, the primary key or foreign key. Then I can use that information on manual queries to the database to fill in other areas of the JFrame.
combodb.JPG
combodb.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://java.sun.com/javase/6/docs/api/javax/swing/JComboBox.html
ASKER
Hi fsze88 that worked. Please view the image. Do you know how to get the specific primary key value if I do click on one out of the list, as I will want to store it inside a variable. I get the classname and tablename showing up as well as the primary keys.
combo.bmp
combo.bmp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
private void jComboBox1_itemStateChange d(ItemEven t e) {
String comboBoxValue;
String Parameter;
String[] pair;
int beginIndex, endIndex;
comboBoxValue = String.valueOf( jComboBox1.getItemAt(jComb oBox1.getS electedInd ex() ));
beginIndex = comboBoxValue.indexOf("[") +1;
endIndex = comboBoxValue.indexOf("]") ;
Parameter = comboBoxValue.substring(be ginIndex,e ndIndex);
System.out.println("Parame ter : " + Parameter);
pair = Parameter.split("=");
System.out.println("value of figher : " + pair[1]);
// System.out.println(e.toStr ing() + e.getStateChange());
// System.out.println(jComboB ox1.getIte mAt(jCombo Box1.getSe lectedInde x() )) ;
}
String comboBoxValue;
String Parameter;
String[] pair;
int beginIndex, endIndex;
comboBoxValue = String.valueOf( jComboBox1.getItemAt(jComb
beginIndex = comboBoxValue.indexOf("[")
endIndex = comboBoxValue.indexOf("]")
Parameter = comboBoxValue.substring(be
System.out.println("Parame
pair = Parameter.split("=");
System.out.println("value of figher : " + pair[1]);
// System.out.println(e.toStr
// System.out.println(jComboB
}
:-)