Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dynamic loading of a JComboBox

25 views
Skip to first unread message

bruce

unread,
Oct 15, 2010, 9:30:25 PM10/15/10
to
I'm trying to load a JComboBox from my database. Here is
the scenario that I am using. The JComboBox is NOT being
loaded correctly so, obviously, I'm doing something wrong.
Appreciate some help.

Scenario:

1. Place a JComboBox on a JFrame.
2. Right Click on the JComboBox.
3. Select "Bind" and Click on "elements".
4. Click "Import Data to Form..."
5. Select the database connection to use. [I have the correct
connection set up]
6. Select the table to use.
7. Run the project.
The JComboBox is filled with two items:
Census.Places[placesid=1]
Census.Places[placesid=2]

> My package is "Census"
> NetBeans created is class "Places" that seems to contain code to
handle this dynamic loading.
> My database contains two fields: placeid and place
> Primary Key is placeid, datafield is place.
> There are two records in the database.

So, it looks like I'm close but not close enough!!!

Appreciate any suggestions on what I'm doing wrong and what I need to
get this working.

Thanks...

Bruce

bruce

unread,
Oct 18, 2010, 12:16:19 PM10/18/10
to

Can anyone suggest what I'm doing wrong. The above note is the
scenario I'm using.

Thanks....

Bruce

Ian Shef

unread,
Oct 18, 2010, 4:01:03 PM10/18/10
to
bruce <bru...@bellsouth.net> wrote in news:72c06022-3dfd-464d-b594-
e2b119...@h7g2000yqn.googlegroups.com:

From

http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html

"The default renderer knows how to render strings and icons. If you put
other objects in a combo box, the default renderer calls the toString
method to provide a string to display. You can customize the way a combo
box renders itself and its items by implementing your own ListCellRenderer.
"

Notice that if you don't do anything special, and if your objects are not
String or Icon, then toString() will be used to display your objects.

It looks to me like you need to change Places#toString(), or specify a
different renderer for your JComboBox.

Perhaps someone can help if you would explain what IDE you are using.

markspace

unread,
Oct 18, 2010, 4:57:39 PM10/18/10
to
On 10/18/2010 1:01 PM, Ian Shef wrote:
> Perhaps someone can help if you would explain what IDE you are using.


>> On Oct 15, 9:30 pm, bruce<bruc...@bellsouth.net> wrote:
>>> > NetBeans created is class "Places" that seems to contai


I'm guessing "NetBeans."

bruce

unread,
Oct 18, 2010, 6:08:35 PM10/18/10
to

Yes, the IDE is NetBeans, 6.9.1.

Thanks for the response.

Bruce

0 new messages