[英]how to filter content in 2nd combo box according to 1st combo box selection
[英]How can I add 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);
}
顯示錯誤
沒有為 DefaultComboBoxModel(String) 找到合適的構造函數。
通過這種方式,您可以從第一個組合框中獲取所選項目並將其添加到第二個組合框中,但我認為您無法取回數組名稱。
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.