File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes problem in JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem in JComboBox" Watch "problem in JComboBox" New topic

problem in JComboBox

Anagha Medicharla

Joined: Feb 06, 2001
Posts: 11
Hi everybody,
I am using JComboBox for user to select state in US.what i want to do is if user selects 'ALABAMA' then text in combobox should set to 'AL'.Does anybody know how to do tis?

Thanx in advance.
selvas kumars
Ranch Hand

Joined: Jan 06, 2001
Posts: 115
what you can do is get the item selected by
using getSelectedItem() of JComboBox and and call toString() method on it and call the substring(0,2) on it...
Now you will get only first 2 characters..
try out this ........
Anagha Medicharla

Joined: Feb 06, 2001
Posts: 11
Hi Selvas,
Thanks for your reply. I tried your code.
But it's throwing java.lang.StackOverflowError.
I have written the code as folllows.
jcomboState.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(ItemEvent e) {
void jcomboState_itemStateChanged(ItemEvent e) {

Can you help me out further.Why is it throwing that exception?

Sajee Joseph
Ranch Hand

Joined: Jan 17, 2001
Posts: 200
I feel that u get the erreor due to the following reason:
Since u r chaing the selected item at
void jcomboState_itemStateChanged(ItemEvent e)
This code will again trigger the jcomboState_itemStateChanged method and this happens infinitely
Hope u got it
I agree. Here's the link:
subject: problem in JComboBox
It's not a secret anymore!