How can I add an array value into 2nd Combo Box model item, getting the array name from 1st Combo Box selected item?
String[] one = new String[]{"A","B"};
String[] two = new String[]{"C","D"};
String[] three = new String[]{"12500","13500"};
String[] four = new String[]{"Scale_1","Scale_2"};
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
String Value=(String)jComboBox1.getSelectedItem();
DefaultComboBoxModel dm=new DefaultComboBoxModel(Value); // here is the error
jComboBox2.setModel(dm);
}
Error showing
no suitable constructor found for DefaultComboBoxModel(String).
This way you can get the selected item from the first combobox and add it to the second one, but I dont think you can get back the array name.
String[] one = new String[]{"A","B"};
String[] two = new String[]{"C","D"};
String[] three = new String[]{"12500","13500"};
String[] four = new String[]{"Scale_1","Scale_2"};
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
String value=(String)jComboBox1.getSelectedItem();
DefaultComboBoxModel dm=(DefaultComboBoxModel)jComboBox2.getModel();
dm.addElement(value);
jComboBox2.setModel(dm);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.