Solved

JComboBox problem

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
nestparen challenge 4 56
word0 challenge 4 54
Starting to learn JAVA, 7 48
Error with Java/Cache JDBC Classpath 2 20
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 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

23 Experts available now in Live!

Get 1:1 Help Now