Results 1 to 4 of 4
Thread: Jcombobox an empty row
- 06-06-2012, 11:14 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Jcombobox an empty row
Hello Every One....
I am new in java and i am making a goods intake form for a company.. my question is when I load the data from database to a Jcombobox, the combobox always show the first record.. (displayed in the jcombobox)
I want an empty row at the to be displayed in the combobox at the top of the combobox and if user has selected any item then this empty space should disappear... (sorry for the language i dont have a very good comman over english)....
by the way the code is below
Java Code:private void setComboBoxForProduct(){ Products.getProductsForCombo(); cmbProductName = new JComboBox<Object>(); for(int i = 0; i<Products.productName.size(); i++){ cmbProductName.addItem(Products.productName.get(i)); } cmbProductName.setEditable(true); cmbProductName.addItemListener(this); new ComboBoxAutoFill(cmbProductName); } //item listener on combobox public void itemStateChanged(ItemEvent ie){ if(ie.getStateChange() == ItemEvent.SELECTED){ productID = Products.productID.get(cmbProductName.getSelectedIndex()); productType = Products.productType.get(cmbProductName.getSelectedIndex()); if(productType.equals("Chilled")) rdoChilled.setSelected(true); else if(productType.equals("Ambient")) rdoAmbient.setSelected(true); } }
Thank you very much for viewing the code
Thanks
Usman
-
Re: Jcombobox an empty row
Before you add the ItemListener to the JComboBox and after adding your items, try setting the JComboBox's selected index to -1 via cmbProductName.setSelectedItem(-1).
- 06-06-2012, 11:40 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Re: Jcombobox an empty row
Thanks alot Fubarable.... that works i actuall used setSelectedIndex(-1)... and that is what i want ... thanks a ton...
-
Similar Threads
-
mysql empty set
By cucucur in forum JDBCReplies: 0Last Post: 04-25-2011, 03:01 PM -
Empty JFrame
By Wednesday Bass in forum AWT / SwingReplies: 2Last Post: 03-25-2011, 07:30 PM -
Activate JComboBox 1 when object is selected in JComboBox 2...
By bahumbaba in forum AWT / SwingReplies: 2Last Post: 12-10-2009, 01:58 PM -
empty arrays.
By circuspeanuts in forum New To JavaReplies: 11Last Post: 04-06-2009, 07:08 PM -
KeyBindings Empty Key?
By Unome in forum Java AppletsReplies: 1Last Post: 10-24-2008, 07:28 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks