Results 1 to 1 of 1
Thread: Adding items to a jComboBox
- 08-08-2007, 08:48 AM #1
Member
- Join Date
- Aug 2007
- Posts
- 1
- Rep Power
- 0
Adding items to a jComboBox
What is the preferred way of adding new items to a jComboBox? I am learning to use Swing and the NetBeans IDE. When coding Swing from scratch, you can add new items in the jComboBox's constructor. However, when I let NetBeans create the code for me, this is in a guarded block and I cannot edit it. By default { "Item 1", "Item 2", "Item 3", "Item 4" } are added to the combobox. The workaround I'm using is to removeAllItems() when the window is first activated. Then add my own items to the list.
Is there a better way of accomplishing this?Java Code:private void formWindowActivated(java.awt.event.WindowEvent evt) { jComboBox1.removeAllItems(); jComboBox1.addItem("red"); jComboBox1.addItem("blue"); jComboBox1.addItem("green"); jComboBox1.addItem("yellow"); }
Thanks
--Donovan
Similar Threads
-
Display items in the JCombo Box
By eddy001 in forum AWT / SwingReplies: 1Last Post: 01-21-2008, 12:27 AM -
Using Enumeration to get items out of the session
By Java Tip in forum Java TipReplies: 0Last Post: 01-04-2008, 09:34 AM -
Is it possible to get and store items to a variable in a combo box?
By Soda in forum New To JavaReplies: 2Last Post: 12-05-2007, 01:19 PM -
hyperlinks from menu items?
By asterope118 in forum New To JavaReplies: 1Last Post: 07-16-2007, 01:49 PM -
Help with jComboBox
By Marcus in forum AWT / SwingReplies: 2Last Post: 07-01-2007, 11:08 PM


LinkBack URL
About LinkBacks

Bookmarks