actionlisteners for 2 comboboxes

I have to comboboxes name, accountnumbers that have information in them. If I pick a name like msaenz, it will give me the accountnumbers to go with it and I have it do vice versa. however when i pick a name and an account number and if that account number has another person pointed to it, it changes the namefield. its basically like tag. I have this code for the actionlisteneres but do not know really what to do to check on the other. I also have a reset button to set the comboboxes to their original state. i was thinking maybe a counter? I don't know any ideas would be wonderful.. thanks for your help all of you who have seen my numerous posts.......

//first combo box name.. i have a hashmap with the accounts and names that are related to each other that i get from a db....and i call them from the testsql class

if ((event.getActionCommand().equals("no"))){

for (String key:TestSQL.theMap().keySet())

{

check=(String) getNames().getSelectedItem();

if (check.equals(key)){

value = TestSQL.theMap().get( key );

}

}

value.add("");

values=(String[]) value.toArray(new String[value.size()]);

getCuentas2().setModel(new JComboBox(values).getModel());

}

//second class....

if ((event.getActionCommand().equals("yes"))){

for (String key:TestSQL.theMap2().keySet())

{

check=(String) getAccounts().getSelectedItem();

if (check.equals(key)){

entry= TestSQL.theMap().get( key );

}

}

entrys=(String[]) entry.toArray(new String[entry.size()]);

getCuentas2().setModel(new JComboBox(values).getModel());

}

[2460 byte] By [h2opologirly69a] at [2007-11-27 8:20:25]
# 1
can anyone help me on this issue?
h2opologirly69a at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 2
I don't understand what is the problem.Try rephrasing your question, or better post a Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the problem. http://homepage1.nifty.com/algafield/sscce.html
Rodney_McKaya at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 3

i have two comboboxes..name and account. i pick a name in the combobox and it gives me the accounts listed and I can do vice versa. However if I pick lets say an accountnumber and i want to pick a name as well it wil not let me select the person I want instead goes to the first person that account is referenced to.

example:

i pick harry, accounts 12345,67896,..

now i pick account 67896 and now the name leaves harry and goes to his wife mary. but i want harry not his wife. but when i pick harry it gives me 12345 not the account I want. So the actions listeners just battle it out. I think I may need a counter or something, but don't know how to really code it in the actionlistener

h2opologirly69a at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 4
You should change your listener a bit.Before you set a new model for the other combo box get the selected item.Then after you set the new model call setSelectedItem with the previously selected item, if it exists in the model.
Rodney_McKaya at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 5
can you clarify that with an example..... i think i got what part of what you are saying ...but im still abit confused.
h2opologirly69a at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 6
I still have no idea what you question is about and am waiting for a SSCCE.
camickra at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 7

import javax.swing.*;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.TextField;

import java.awt.event.*;

import javax.swing.ComboBoxModel;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JComboBox;

import javax.swing.JCheckBox;

import javax.swing.JTable;

import javax.swing.JTextArea;

import javax.swing.table.DefaultTableModel;

import java.awt.Dimension;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Calendar;

import java.util.Date;

import java.util.HashMap;

import java.util.HashSet;

import java.util.Hashtable;

import java.util.Iterator;

import java.util.Map;

import java.util.Set;

import javax.swing.JRadioButton;

import javax.swing.JTextPane;

import javax.swing.JTextField;

public class Test extends JTabbedPane implements ActionListener {

private static final long serialVersionUID = 1;

/*****Tab2****/

JPanel MainPanel;

JPanel jPanel2;

JTable table;

DefaultTableModel model;

JComboBox TablasBox;

JLabel Tablas;

JPanel extra = null;

JPanel trads = null;

JComboBox traders = null;

JPanel accounts = null;

JComboBox cuentas2 = null;

String []ops={"","=","between", "and", "where","<", ">", "<=", ">=", "in"};

JButton updateQuery;

TestSQL examen;

static Hashtable<String, JCheckBox> checkboxes=new Hashtable<String,JCheckBox>();

private JComboBox jComboBox = null;

private JPanel accnttrd = null;

String check;

String lool;

Set<String> value;

String[] values;

Set <String> answer;

String [] things;

Calendar cal;

Date today;

Date yesterday;

SimpleDateFormat sqlFormat;

String todayString;

String yesterdayString;

public Test() {

super();

setVisible(true);

initialize();

}

/**

* This method initializes this

*

* @return void

*/

private Map < String, Set < String > > map = new HashMap < String,

Set < String > > ();

public boolean put(String key, String value) {

Set<String> values = map.get(key);

if (values == null)

map.put(key, values=new HashSet < String > ());

return values.add(value);

}

public String toString() {

return map.toString();

}

public Map < String, Set < String > > theMap(){

Test m = new Test();

m.put("alex", "12345");

m.put("vivian", "12345");

m.put("teacher", "98741");

m.put("harry", "65789");

m.put("steve", "54652");

m.put("teacher", "54652");

return m.map;

}

public Map < String, Set < String > > theMap2(){

Test m = new Test();

m.put("12345", "alex");

m.put("12345", "vivian");

m.put("98741", "teacher");

m.put("65789", "harry");

m.put("54652", "steve");

m.put("54652", "teacher");

m.put("98741","vivian");

return m.map;

}

public void initialize() {

this.setSize(1118, 419);

this.addTab("GUI",null, getMainPanel(), null);

}

String[] nombres={"alex","vivian","teacher","harry"};

String[] accountnum={"12345","98741","65789","54652"};

/**

* This method initializes jPanel1

*

* @return javax.swing.JPanel

*/

public JPanel getMainPanel() {

if (MainPanel == null) {

FlowLayout flowLayout1 = new FlowLayout();

flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);

flowLayout1.setVgap(3);

flowLayout1.setHgap(3);

MainPanel = new JPanel();

MainPanel.setLayout(flowLayout1);

MainPanel.setPreferredSize(new java.awt.Dimension(900,300));

MainPanel.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);

MainPanel.setVisible(true);

MainPanel.add(getAccnttrd(), null);

}

return MainPanel;

}

private JPanel getTrads() {

if (trads == null) {

GridLayout gridLayout11 = new GridLayout();

gridLayout11.setRows(8);

GridLayout gridLayout = new GridLayout();

gridLayout.setRows(8);

trads = new JPanel();

trads.setLayout(gridLayout11);

trads.setPreferredSize(new java.awt.Dimension(100,189));

trads.setVisible(true);

trads.add(getTraders(), null);

}

return trads;

}

JComboBox getTraders() {

if (traders == null) {

traders = new JComboBox(nombres);

traders.setEditable(false);

traders.setPreferredSize(new java.awt.Dimension(60,20));

traders.addActionListener(this);

traders.setActionCommand("no");

}

return traders;

}

private JPanel getAccounts() {

if (accounts == null) {

GridLayout gridLayout14 = new GridLayout();

gridLayout14.setRows(8);

accounts = new JPanel();

accounts.setPreferredSize(new java.awt.Dimension(100,189));

accounts.setLayout(gridLayout14);

accounts.add(getCuentas2(), null);

accounts.setVisible(true);

}

return accounts;

}

private JComboBox getCuentas2() {

if (cuentas2 == null) {

cuentas2 = new JComboBox(accountnum);

cuentas2.setPreferredSize(new java.awt.Dimension(60,20));

cuentas2.setEditable(false);

cuentas2.addActionListener(this);

cuentas2.setActionCommand("cuentas2");

}

return cuentas2;

}

/**

* This method initializes accnttrd

*

* @return javax.swing.JPanel

*/

private JPanel getAccnttrd() {

if (accnttrd == null) {

FlowLayout flowLayout = new FlowLayout();

flowLayout.setAlignment(java.awt.FlowLayout.LEFT);

flowLayout.setVgap(2);

flowLayout.setHgap(2);

accnttrd = new JPanel();

accnttrd.setPreferredSize(new java.awt.Dimension(330,190));

accnttrd.setVisible(true);

accnttrd.setLayout(flowLayout);

accnttrd.add(getTrads(), null);

accnttrd.add(getAccounts(), null);

}

return accnttrd;

}

public static String checkCaja()

{

String temp="";

for(String name:checkboxes.keySet()){

//System.out.println(checkboxes.get(name).isSelected()+name);

if (checkboxes.get(name).isSelected()==true)

{

temp=temp+name+",";

}

}

if(temp.length() > 0) {

temp = temp.substring(0, temp.length() - 1);

}

//System.out.print(temp);

return temp;

}

public void actionPerformed(ActionEvent event) {

if ((event.getActionCommand().equals("no"))){

for (String key: theMap().keySet())

{

check=(String) getTraders().getSelectedItem();

if (check.equals(key)){

value = ((Map<String,Set><String>>) theMap()).get( key );

}

}

values=(String[]) value.toArray(new String[value.size()]);

getCuentas2().setModel(new JComboBox(values).getModel());

}

if ((event.getActionCommand().equals("cuentas"))){

for (String key: theMap2().keySet())

{

lool=(String) getCuentas2().getSelectedItem();

if (lool.equals(key)){

answer = ((Map<String,Set><String>>) theMap2()).get( key );

}

}

things=(String[]) value.toArray(new String[value.size()]);

getTraders().setModel(new JComboBox(things).getModel());

}

}

}

h2opologirly69a at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 8

if you choose accounts first if you pick 12345 it has alex and vivian attached to it. but after i pick 12345 i would like to have vivian. but then it will change back to alex. if i choose name first it will list the proper account number but then if i pick one with more than one person to it, then it will gi ve me the first person not the one i chose.. see back and forth like tag.

h2opologirly69a at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 9
I have a SSCCE up there if you dont mind taking a look at it. thank you.
h2opologirly69a at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 10
I tried, but I don't use JDK1.5 and converting all the generics code was too time consuming,
camickra at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 11
thanks for trying.....
h2opologirly69a at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...
# 12
anyone else?
h2opologirly69a at 2007-7-12 20:08:43 > top of Java-index,Desktop,Core GUI APIs...