Results 1 to 1 of 1
Thread: problem w/ multiple jcombobox
- 05-06-2011, 06:47 AM #1
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
problem w/ multiple jcombobox
Hi guys, im a newbie in this forum.
I've been working with a project that requires me to use mutiple jcombobox. I did try to relate three jcombobox but failed to show all necesarry drop-down lists.
In one of my combobox I have lists of Banks (Bank1, Bank2), the other one is the list of all branches in a specific Bank that has been selected (Bank1(branch1-1, branch1-2), Bank2(branch2-1, branch2-2)) and the last one are the account # for all specific branches that has been selected. each branches have a multiple accounts. I have no problem working with 2 comboboxes, all branches are shown for a specific Bank that has been selected, but, when I added the third combobox which is the account #, only one branch is being queried from my db. ex. if I select Bank1 only "branch1-1" will be on the list, and if Bank2 only branch2-1 will be on the list also, but account # for that specific branches are on the drop-down lists.
here's my code:
private void populateSavingsAccountComboBox(){
accountNo.removeAllItems();
bankBranch.removeAllItems();
selectBank();
bankName.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String bank = bankName.getSelectedItem() == null ? "" : bankName.getSelectedItem().toString();
selectBranch(bank);
}
});
bankBranch.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
Object source = e.getSource();
JComboBox target = (JComboBox)e.getSource();
String branch = target.getSelectedItem() == null ? "" : target.getSelectedItem().toString();
if (e.getStateChange() == ItemEvent.SELECTED){
selectAccountNo(bankName.getSelectedItem().toStrin g(), branch);
}
}
});
}
private void selectBank(){
List bankList = new ArrayList();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(" SELECT bankName FROM bank_tbl ");
bankName.removeAllItems();
while (rs.next()) {
String bank = rs.getString("bankName");
bankList.add(bank);
Object bankElement = bankList.get(bankList.size() - 1);
bankName.addItem(bankElement);
}
} catch (SQLException ex) {
Logger.getLogger(addSavings.class.getName()).log(L evel.SEVERE, null, ex);
}
}
private String selectBranch(String bank){
try {
List branchList = new ArrayList();
rs = stmt.executeQuery(" SELECT branch FROM bank_branch_tbl WHERE "
+ " bankName = '" + bank + "' ");
bankBranch.removeAllItems();
while (rs.next()) {
branchList.add(rs.getString("branch"));
Object branchElement = branchList.get(branchList.size()-1);
bankBranch.addItem(branchElement);
}
} catch (SQLException ex) {
Logger.getLogger(addContact.class.getName()).log(L evel.SEVERE, null, ex);
}
return bank;
}
private String selectAccountNo(String bank, String branch){
List accountNoList = new ArrayList();
try {
rs = stmt.executeQuery(" SELECT accountNo FROM account_no_tbl WHERE "
+ " bankName = '"+bank+"' AND "
+ " branch = '"+branch+"' ");
accountNo.removeAllItems();
while(rs.next()){
accountNoList.add(rs.getString("accountNo"));
Object accountNoElement = accountNoList.get(accountNoList.size()-1);
accountNo.addItem(accountNoElement);
}
} catch (SQLException ex) {
Logger.getLogger(addSavings.class.getName()).log(L evel.SEVERE, null, ex);
}
return branch;
}
Similar Threads
-
problem in jComboBox
By jperson in forum JDBCReplies: 1Last Post: 05-19-2010, 01:30 PM -
ItemListener problem with JComboBox
By al_Marshy_1981 in forum AWT / SwingReplies: 3Last Post: 04-16-2010, 10:24 PM -
Serious Problem with JComboBox
By Plissken in forum New To JavaReplies: 3Last Post: 02-02-2010, 10:48 AM -
Problem with Jcombobox in Tablecell
By yernikumar in forum AWT / SwingReplies: 1Last Post: 03-19-2009, 08:00 AM -
Accessibility of JComboBox problem
By abedules78 in forum AWT / SwingReplies: 0Last Post: 12-26-2008, 01:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks