Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-08-2007, 09:48 AM
Member
 
Join Date: Aug 2007
Posts: 1
tronovan is on a distinguished road
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.

Code:
private void formWindowActivated(java.awt.event.WindowEvent evt) { jComboBox1.removeAllItems(); jComboBox1.addItem("red"); jComboBox1.addItem("blue"); jComboBox1.addItem("green"); jComboBox1.addItem("yellow"); }
Is there a better way of accomplishing this?

Thanks
--Donovan
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display items in the JCombo Box eddy001 AWT / Swing 1 01-21-2008 01:27 AM
Using Enumeration to get items out of the session Java Tip Java Tips 0 01-04-2008 10:34 AM
Is it possible to get and store items to a variable in a combo box? Soda New To Java 2 12-05-2007 02:19 PM
hyperlinks from menu items? asterope118 New To Java 1 07-16-2007 02:49 PM
Help with jComboBox Marcus AWT / Swing 2 07-02-2007 12:08 AM


All times are GMT +3. The time now is 02:11 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org