User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,443 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,624 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 392 | Replies: 1
Reply
Join Date: Mar 2007
Posts: 15
Reputation: pmhayden is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
pmhayden pmhayden is offline Offline
Newbie Poster

Question comparing a value to a value in a jComboBox

  #1  
Sep 5th, 2007
I have a ComboBox defined as follows:

private String[] months = {"Month", "01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12"};
private JComboBox jComboBoxMonth = null;

and down further I have:

jComboBoxMonth = new JComboBox(months);

Now i am trying to do run an if statement which checks to see if the word "Month" is what is appearing in the ComboBox. So down further I have:

if (jComboBoxMonth.equals("Month") {
and my code is here.

Is the above test in the if statement being carried out, as i suspect that it isn't.

Anyone any ideas.

Thanks
Paidi
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,628
Reputation: peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice 
Rep Power: 12
Solved Threads: 311
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: comparing a value to a value in a jComboBox

  #2  
Sep 5th, 2007
No, you have to first call currently selected item
String selectedOption = (String) jComboBoxMonth.getSelectedItem()
and then you can compare it as you did it
if (selectedOption.equals("Month")
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 1:46 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC