Results 1 to 5 of 5
- 12-08-2012, 04:36 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 55
- Rep Power
- 0
Cant figure out how to write an if statement for combobox
Hello, i have a form witch has 3 ComboBoxes 1 TextField and 1 TextArea.
These ComboBoxes have values, but the first value in each box is a blank value (i made it this way).
I need to check in my if statement, if even one value from these combo boxes are set for the first value (blank one).
For textfield i just check like this - 'if (textfield.getText().isEmpty()'. Will this work for TextArea aswell? (i mean the isEmpty part).
- 12-08-2012, 05:40 PM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Cant figure out how to write an if statement for combobox
To get the selected item from JComboBox you can use getSelectedItem(). If your JComboBox items are strings can cast object returned by the getSelectedItem() method to string.
Website: Learn Java by Examples
- 12-08-2012, 05:59 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 55
- Rep Power
- 0
Re: Cant figure out how to write an if statement for combobox
Thanks, it works.
Used like this:
(My first item is " ")Java Code:if (combobox.getSelectedItem().equals(" ")){ }Last edited by iNko; 12-08-2012 at 06:02 PM.
- 12-08-2012, 06:02 PM #4
Re: Cant figure out how to write an if statement for combobox
Or if you're on Java SE 7 you can use Generics and have no need for casting.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-08-2012, 06:03 PM #5
Similar Threads
-
how to embed combobox,checbox in JTable read write to database
By scorpion.poison in forum New To JavaReplies: 4Last Post: 08-30-2012, 10:52 AM -
Please Help... switch statement not recognising variable..and I can't figure out why
By HereIam in forum New To JavaReplies: 7Last Post: 02-14-2012, 10:12 AM -
Can't figure out how to write this program.
By Quinn in forum New To JavaReplies: 18Last Post: 05-18-2011, 09:04 PM -
Can't figure out why my Else statement won't work
By basla in forum New To JavaReplies: 6Last Post: 03-31-2011, 03:33 PM -
How to Write this if statement?
By PeterFeng in forum New To JavaReplies: 1Last Post: 01-14-2009, 07:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks