Results 1 to 7 of 7
Thread: ComboBoX dropdown
- 03-30-2011, 11:04 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 23
- Rep Power
- 0
ComboBoX dropdown
Hi,
I have a frame with a combobox. the combox is editable. It should show [Select] in its text field when we open the frame but in the drop down, [Select] should not be shown as a drop down item.
Now I have implemented the combobos as:
combo.addItem("Select");
combo.addItem("A");
combo.addItem("B");
and so on...
But the Select is an item and will be shown in the drop down
Can anyone help me plz....
- 03-30-2011, 03:47 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
The Combo Box Prompt might be what you are looking for.
- 03-31-2011, 07:19 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 23
- Rep Power
- 0
Yes...Its the same thing I wanted..
Now my code part looks like this..
combo.addItem("A");
combo.addItem("B");
combo.setRenderer(new PromptComboBoxRenderer("Select "));
Did I missed something???It doesnt seem to work...
Thnks fr the help...
- 03-31-2011, 03:50 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
You didn't miss anything. Only a single line of code is required. It was tested on XP using JDK6.7.
Post your Short, Self Contained, Correct Example that demonstrates the problem.
- 04-07-2011, 12:31 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 23
- Rep Power
- 0
Hi,
I am involved in a project for creating a library database.
My exact code looks like this:
public combobox()
{
JFrame frame = new JFrame("Library Database");
String Books[] = {"Maths","Physics","Chemistry","Commerce"};
Panel panel = new JPanel();
combo = new JComboBox(Books);
combo.setRenderer(new PromptComboBoxRenderer("[Select] "));
panel.add(combo);
}
and this selelcted item is used for display in a text field. But it doesn't work.
Thanks for ur help once again...
- 04-07-2011, 03:37 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
The combo box selects the first item by default. Once you've set the renderer and the items into the combo box, clear the default selection:
Java Code:combo.setSelectedIndex(-1);
- 04-08-2011, 05:53 AM #7
Member
- Join Date
- Mar 2011
- Posts
- 23
- Rep Power
- 0
Similar Threads
-
dropdown with other option
By vallaru in forum Web FrameworksReplies: 1Last Post: 02-28-2011, 09:00 AM -
dropdown onchange
By srivempala in forum New To JavaReplies: 0Last Post: 01-23-2011, 11:54 AM -
dynamically populate a dropdown box using jsp
By sandy1000 in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 12-27-2010, 02:21 PM -
To populate dropdown in Struts 1.3.8
By techV in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-27-2010, 08:49 AM -
Help with dropdown list
By barney in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 07:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks