comboBox asnafのアイテムを表示するコンボボックスからアイテムを選択したいと思いますが、アイテムは2回表示され、コンボボックスの名前から別のアイテムを選択するとそれは上記の画像に示されているようにように、他の項目は、前の項目に追加..これは私のコード2つのjcomboboxをリンクせずに値を繰り返す方法
public void agent_comboBoxA() {
try {
String sql = "select * from `trading`";
myStmt = connection.prepareStatement(sql);
rs = myStmt.executeQuery();
while (rs.next()) {
String agent = rs.getString("agent_name");
names.addItem(agent);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void kind_comboBoxA()
{
String sql = "select kind from trading where agent_name = ?";
try {
myStmt = connection.prepareStatement(sql);
myStmt.setString(1,String.valueOf(names.getSelectedItem()));
rs = myStmt.executeQuery();
while (rs.next()) {
String kind = rs.getString("kind");
asnaf.addItem(kind);
}
}catch (SQLException e) {
e.printStackTrace();
}
}
public the defualt Constructor {
agent_comboBoxA();
names.addItemListener(e -> {
kind_comboBoxA();
});
}
this when repeat the same value
this when repeat the same value and the other value
私はここでエラーを見ることができます: 'public the defualt Constructor'。それともデモンストレーションですか? –
はいただのデモンストレーション@YoungMillie –