Solved

JComboBox problem

Posted on 2007-03-29
1
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

751 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