populate combo box with value in database of selected user

hi i have situation where i what to populate use status based on the value in database
 
if the user status = Active{
i what to make other select to be inactive and it must load with the user status in database
 
this is what i have done
private JComboBox<String> statusCombo = null;

DusernameLabel  = new JLabel("Username");
        Dusername = new JComboBox<>();
        DstatusLabel= new JLabel("Status");
        DustatusCombo = new JComboBox<>();
        DustatusCombo.addItem("Active");
		DustatusCombo.addItem("Inactive");
        dUpdate = new JButton("Save"){
        {
        	setSize(5, 8);
	            
	        setMinimumSize(getSize());
        }
        }; 
		
		 DusernameLabel.setBounds(1,30,150,20);
       Dusername.setBounds(70,30,150,20);
       Dusername.setEditable(true);
       DstatusLabel.setBounds(1,70,100,20) ;	
       DustatusCombo.setBounds(70,70,150,20);
       dUpdate.setBounds(100,140,80,20);
	   
	   jp3.setLayout(null);
       // jp3.add(label3);
        jp3.add(DusernameLabel);
        jp3.add(Dusername);
        jp3.add(DstatusLabel);
        jp3.add(DustatusCombo);
        jp3.add(dUpdate);
		
		  DustatusCombo.addItemListener(itemListener);
        Map<String,DBObject> uStatus = dao.findStatus();
        for(String key : uStatus.keySet()){
        	
        	DustatusCombo.addItem(key);
        }
		
		public Map<String, DBObject> findStatus()
	{
		cursor = collection.find();
		
		Map<String, DBObject> uStatus = new HashMap<>();
		
		
		uStatus.equals(uStatusT);
		
		while(cursor.hasNext())
			{
			DBObject dbObj = cursor.next();
			uStatus.put((String)dbObj.get("status"), dbObj);
			}	
	return uStatus;
	}

Open in new window

status
chalie001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
You would need to listen for an event on the first combobox and populate the data in the second one accordingly.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chalie001Author Commented:
how do i listen for an event if i change username in combobox it must also change the status
gurpsbassiCommented:
Using ItemListener, the same code you posted in the other question.

listen for the event, then change the values in the other jcombobox depending on the value of the first.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

chalie001Author Commented:
yes how can i do that, where must i put the if statement and how
 
dstatusCombo.addItemListener(itemListener);
        Map<String,DBObject> uStatus = dao.findStatus();
        for(String key : uStatus.keySet()){
        	
        	dustatusCombo.addItem(key);
        }

Open in new window

gurpsbassiCommented:
You need the listener on the FIRST combo box i.e. the usernames one!

Then within the implementation of the listener, you need to populate the second combo box of statuses
chalie001Author Commented:
you mean this
Dusername.addItemListener(itemListener);
        DustatusCombo.addItemListener(itemListener);
       Map<String, DBObject> alluserU = dao.findAllusersDb();
        for(String key :  alluserU.keySet()){
        	Dusername.addItem(key);
        }
        
       
        Map<String,DBObject> uStatus = dao.findStatus();
        for(String key : uStatus.keySet()){
        	
        	DustatusCombo.addItem(key);
        }

Open in new window

gurpsbassiCommented:
No


for a start please change your variable names.

Don't you think usernameComboBox is better than Dusername ?
CEHJCommented:
Why would you be asking such a closely related question to an already open question of yours - especially when that question is not nearly (even now) concluded?
gurpsbassiCommented:
Why would you be asking such a closely related question to an already open question of yours - especially when that question is not nearly (even now) concluded?

I agree with you CEHJ.

I am finding it difficult to manage these questions myself. I am helping @chalie001 on question A and he/she raises more questions (B, C , D) on the same code. The code then changes in question B, C, D and I have to keep track of whats going on. Its proving difficult!
CEHJCommented:
I am finding it difficult to manage these questions myself. I am helping @chalie001 on question A and he/she raises more questions (B, C , D) on the same code.
B, C and D should be ignored and closed, particularly when they depend on the correctness of A.

Let me make a suggestion (which i tried to make happen MANY posts ago): the task in hand is to make a 'User' DTO from the database and to prove that the same can be used in the list model of a combo box in the gui. Anything else should be ignored until that's demonstrably done.
chalie001Author Commented:
Thanks for trying  to help I got it
chalie001Author Commented:
I listen for an event on the first combobox and populate the data in the second one
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.