Solved

JComboBox problem

Posted on 2007-03-29
1
276 Views
Last Modified: 2010-03-31
Here's the scenario.
I have an object (plan) which contains (string = type of plan, int = price)
I have a gui that lists the plans in a JList and u can click on them and do whatever .
Now i would like to add a filter to it because there are over 500 plans and to scroll down to teh one u need is a pain in the butt.
So i made the filter... its the same concept as the firefox search option... as u type letters it searches for the latest match.
I did this in a JComboBox where i type plan name in the box and its supposed to scroll down to
So i type the name of the plan.. and it scrolls down to it and selects it but once i hit enter ( to verify that its the one i want to select) it doesnt close the combobox drop dow menu and leave the selected lpan int he textfield but instead it shows me the entire object... such as " plan=Info,price=2.03" when its only supposed to say "Info" which is taken from the dropdown menu.

Does anyone know what i have to do to get the names and not the entire object to appear in the textfield after dropdown menu from the combobox goes away?

some of my code

        jbox = new JComboBox();
        jbox.setModel(modelPlans);
        jbox.setRenderer( new PlanBeanCellRenderer() );
       
OK tbove code SUCCESSFULLY gives the drop down menu from the jcombobox and i can click on a item and it will appear in the textfield ONLY if the next line is true
             jbox.setEditable(false);

But this gives an uneditable JComboBox where i cant type to filter stuff out... so that defeats the purpose...
i need to have
        jbox.setEditable(true);
However that just displays the entire object on the textfield...

any ideas anyone? or was that too general?
0
Comment
Question by:Squadless
1 Comment
 
LVL 10

Accepted Solution

by:
ADSLMark earned 500 total points
ID: 18819890
I think the problem lies somewhere outside the code you post here.
I was trying to reproduce your bug with my own code, but i don't seem to run into any problems, then again, my example was small and not very advanced. I guess you call thefunction toString() or set the text of the combobox with setText() and there you pass the whole object, maybe that should be just the value you want to show.. then again, I'm not sure how your code looks like.

Mark
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question