Solved

JComboBox problem

Posted on 2007-03-29
1
272 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now