aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to handle more than two combobox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to handle more than two combobox" Watch "How to handle more than two combobox" New topic
Author

How to handle more than two combobox

Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
Hi,

I have 4 combo box and m adding values to combo box depending on previous combo box value.
n when user selects another value in same combo box i just called removeAllItems(); on combo box.so that previous values gets deleted. .it is working for only 2 combo boxes.
but it gives null pointer exception for more than 2 combo box. This is because when i called removeallItems() then actionlister is called automatically. n i hav written query for adding values to that in actionlistener.
so how should i handle these combo boxes??
thanks in advance...
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 563
Can you show some code?


Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
Thanks Greq,

see I have combo boxs for Person Name,Person Id,and Receipt No.

I have added person names to combo in constructor.



Next In ActionListener of first combo box i hav added customer id into 2nd combo box.
like


up to this it is working fine...then according to customer id i wants to select receipt no.
so in actionlistener of 2nd combo box i hav written code like



I got Null pointer exception..


Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Where have you initialized combo_receipt_report?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
thanks maneesh,
I have just added an item like "select report" in constructor...


Main problem is that when i remove items from combo_receipt_report in combo_person_idActionPerformed (LINE NO 4) then actionlistener of combo_receipt_report is called.thats why it is giving null pointer exception..

Thanks...
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1096
    
  10

That indicates a problem in the actionListener code of combo_receipt_report. Based on your other actionListeners, I am thinking you are making a call to: in the actionListener of that combo. Instead you should add a null check. When all the items are removed, there is no item to select - so the getSelectedItem() will return null.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Swela Jathar wrote:thanks maneesh,
I have just added an item like "select report" in constructor...


Main problem is that when i remove items from combo_receipt_report in combo_person_idActionPerformed (LINE NO 4) then actionlistener of combo_receipt_report is called.thats why it is giving null pointer exception..

Thanks...


I don't think you are understanding what I am saying. Have you initialized combo_receipt_report? Something like combo_receipt_report=new JComboBox()
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
ya..i hav initialized it...n then added item to it..
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

With the code you have posted till now it is difficult to say what's going wrong. You can help us help you better by posting a SSCCE code. Please do take out time to click the SSCCE link to find out what it really means.
Andrew flexdeveloper
Greenhorn

Joined: Aug 04, 2011
Posts: 7
Hi friends,

I also face the same problem.

Can you please help me in details?


Flex Development | Flex Developer in India
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
Hi Maneesh,

can you show me some another example which handles more than three combo boxes?
Thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle more than two combobox